Skip to content

Instantly share code, notes, and snippets.

@rdp
Created May 30, 2011 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdp/999252 to your computer and use it in GitHub Desktop.
Save rdp/999252 to your computer and use it in GitHub Desktop.
mirah not checking for the return type correctly
You can see here that mirah compiles it fine, then returns an [odd] NoSuchFieldError, whereas java throws a compile exception. I believe mirah could have spotted this (it returns Object, c is of type RubyObj in this case)
c:\dev\ruby\stevia\lib\temp>C:\dev\ruby\downloads\jruby\bin\jruby C:\dev\ruby\downloads\jruby\bin\mirahc repro
Parsing...
repro
Inferring types...
Compiling...
repro
Done!
c:\dev\ruby\stevia\lib\temp>java Repro
Exception in thread "main" java.lang.NoSuchFieldError: c
at Repro.main(repro:20)
c:\dev\ruby\stevia\lib\temp>javac Repro.java
Repro.java:19: incompatible types
found : java.lang.Object
required: RubyObj
return $binding.c = ((ImplementsPlusOneArg)($binding.c)).plus(n);
^
1 error
class RubyObj
end
interface ImplementsPlusOneArg do
def plus(o:Object)
end
end
interface BlockOneArg do
def call(o:Object)
end
end
class RubyInt < RubyObj
def times(o:BlockOneArg)
end
end
c = RubyObj(nil)
c = RubyInt.new()
RubyInt.new().times do |n|
c = ImplementsPlusOneArg(c).plus n # could also raise at compile time, since it's assigning c to an Object without casting.
end
@rdp
Copy link
Author

rdp commented May 30, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment