Created
May 30, 2011 18:24
-
-
Save rdp/999252 to your computer and use it in GitHub Desktop.
mirah not checking for the return type correctly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://code.google.com/p/mirah/issues/detail?id=68