Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closure with type may produce compiler error #369

Closed
felixvf opened this issue Aug 25, 2015 · 1 comment
Closed

Closure with type may produce compiler error #369

felixvf opened this issue Aug 25, 2015 · 1 comment

Comments

@felixvf
Copy link
Contributor

felixvf commented Aug 25, 2015

Consider this Mirah code:

class Bar
end

interface Foo
    def action(bar:Bar); end
end

class FooCaller

    def with_foo(foo:Foo):void
        foo.action(Bar.new)
    end

    def call_with_foo
        with_foo do |bar:Bar|
            puts "Closure called."
        end
    end
end

FooCaller.new.call_with_foo

it should compile cleanly, but instead the compiler fails with

ERROR: Internal compiler error: java.lang.ClassCastException: org.mirah.jvm.mirrors.MirrorProxy cannot be cast to org.mirah.jvm.mirrors.BaseType org.mirah.jvm.mirrors.MirrorProxy cannot be cast to org.mirah.jvm.mirrors.BaseType. Rerun in verbose mode for stacktrace.
Exception in thread "main" org.mirah.jvm.compiler.ReportedException: java.lang.ClassCastException: org.mirah.jvm.mirrors.MirrorProxy cannot be cast to org.mirah.jvm.mirrors.BaseType
        at org.mirah.jvm.mirrors.SafeTyper.betterException(safe_typer.mirah:72)
        at org.mirah.jvm.mirrors.SafeTyper.betterException(safe_typer.mirah:58)
        at org.mirah.jvm.mirrors.SafeTyper.finish_closures(safe_typer.mirah:55)
        at org.mirah.tool.MirahCompiler.infer(mirah_compiler.mirah:175)
        at org.mirah.tool.MirahTool.compile(mirah_tool.mirah:107)
        at org.mirah.tool.Mirahc.main(mirahc.mirah:34)
        at org.mirah.MirahCommand.compile(mirah_command.mirah:27)
        at org.mirah.MirahCommand.main(mirah_command.mirah:43)
Caused by: java.lang.ClassCastException: org.mirah.jvm.mirrors.MirrorProxy cannot be cast to org.mirah.jvm.mirrors.BaseType
        at org.mirah.typer.BetterClosureBuilder.build_methods_for(better_closures.mirah:1028)
        at org.mirah.typer.BetterClosureBuilder.build_and_inject_methods(better_closures.mirah:1100)
        at org.mirah.typer.BetterClosureBuilder.finish(better_closures.mirah:504)
        at org.mirah.typer.Typer.finish_closures(typer.mirah:75)
        at org.mirah.jvm.mirrors.SafeTyper.finish_closures(safe_typer.mirah:53)
        ... 5 more

Note that the related code

class Bar
end

interface Foo
    def action(bar:Bar); end
end

class FooCaller

    def with_foo(foo:Foo):void
        foo.action(Bar.new)
    end

    def call_with_foo
        with_foo do |bar|
            puts "Closure called."
        end
    end
end

FooCaller.new.call_with_foo

compiles and runs fine.

felixvf pushed a commit to felixvf/mirah that referenced this issue Oct 5, 2015
felixvf pushed a commit to felixvf/mirah that referenced this issue Oct 5, 2015
felixvf added a commit that referenced this issue Oct 5, 2015
@felixvf
Copy link
Contributor Author

felixvf commented Oct 5, 2015

Fixed by #378.

@felixvf felixvf closed this as completed Oct 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant