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

Compiler error when class having macros is abstract #320

Open
felixvf opened this issue Jun 19, 2015 · 1 comment
Open

Compiler error when class having macros is abstract #320

felixvf opened this issue Jun 19, 2015 · 1 comment

Comments

@felixvf
Copy link
Contributor

felixvf commented Jun 19, 2015

Consider this code

interface I1
end

abstract class C2 implements I1
    macro def self.bar
        quote do
            puts "bar"
        end
    end
end

it should compile successfully. But the current mirah compiler yields

src/org/mirah/macros/builder.mirah:216:

ERROR: Type redeclared as org.mirah.macros.Compiler from [org.mirah.macros.Compiler]
          @mirah = mirah
          ^^^^^^
src/org/mirah/macros/builder.mirah:217:

ERROR: Type redeclared as mirah.lang.ast.CallSite from [mirah.lang.ast.CallSite]
          @call = call
          ^^^^^

Related code

interface I1
end

abstract class C2
    macro def self.bar
        quote do
            puts "bar"
        end
    end
end

compiles successfully, as does

interface I1
end

class C2 implements I1
    macro def self.bar
        quote do
            puts "bar"
        end
    end
end
@felixvf
Copy link
Contributor Author

felixvf commented Jun 19, 2015

Further analysis reveals that ClassCleanup is applied twice to class C2, once in

parameters = inferParameterTypes call
and once in
@futures[proxy] = proxy.inferChildren(expression != nil)

as evidenced by these 2 stack traces:

java.lang.Exception
        at org.mirah.typer.AssignableTypeFuture.declare(assignable_type_future.mirah:48)
        at org.mirah.typer.Typer.visitFieldDeclaration(typer.mirah:496)
        at mirah.lang.ast.FieldDeclaration.accept(klass.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.infer(typer.mirah:114)
        at org.mirah.jvm.compiler.ClassCleanup.declareFields(class_cleanup.mirah:154)
        at org.mirah.jvm.compiler.ClassCleanup.clean(class_cleanup.mirah:92)
        at org.mirah.jvm.compiler.ScriptCleanup.enterClassDefinition(script_cleanup.mirah:119)
        at mirah.lang.ast.NodeScanner.visitClassDefinition(meta.mirah)
        at mirah.lang.ast.ClassDefinition.accept(klass.mirah)
        at mirah.lang.ast.NodeScanner.scan(meta.mirah)
        at mirah.lang.ast.NodeScanner.visitNodeList(meta.mirah)
        at mirah.lang.ast.NodeList.accept(lists.mirah)
        at mirah.lang.ast.NodeScanner.scan(meta.mirah)
        at mirah.lang.ast.NodeScanner.visitScript(meta.mirah)
        at mirah.lang.ast.Script.accept(structure.mirah)
        at org.mirah.jvm.compiler.Backend.clean(backend.mirah:64)
        at org.mirah.tool.MirahCompiler.compileAndLoadExtension(mirah_compiler.mirah:205)
        at org.mirah.macros.MacroBuilder.buildExtension(builder.mirah:112)
        at org.mirah.typer.Typer.visitMacroDefinition(typer.mirah:1267)
        at mirah.lang.ast.MacroDefinition.accept(intrinsics.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitNodeList(typer.mirah:828)
        at mirah.lang.ast.NodeList.accept(lists.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitClassDefinition(typer.mirah:478)
        at mirah.lang.ast.ClassDefinition.accept(klass.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)



        at org.mirah.typer.Typer.infer(typer.mirah:127)
        at org.mirah.typer.Typer.infer(typer.mirah:126)
        at org.mirah.typer.Typer.inferAll(typer.mirah:132)
        at org.mirah.typer.Typer.inferParameterTypes(typer.mirah:1436)
        at org.mirah.typer.Typer.visitFunctionalCall(typer.mirah:196)

        at mirah.lang.ast.FunctionalCall.accept(call.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitNodeList(typer.mirah:828)
        at mirah.lang.ast.NodeList.accept(lists.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitScript(typer.mirah:848)
        at mirah.lang.ast.Script.accept(structure.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.tool.MirahCompiler.infer(mirah_compiler.mirah:167)
        at org.mirah.tool.MirahTool.compile(mirah_tool.mirah:108)
        at org.mirah.tool.Mirahc.main(mirahc.mirah:34)

as well as

java.lang.Exception
        at org.mirah.typer.AssignableTypeFuture.declare(assignable_type_future.mirah:48)
        at org.mirah.typer.Typer.visitFieldDeclaration(typer.mirah:496)
        at mirah.lang.ast.FieldDeclaration.accept(klass.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.infer(typer.mirah:114)
        at org.mirah.jvm.compiler.ClassCleanup.declareFields(class_cleanup.mirah:154)
        at org.mirah.jvm.compiler.ClassCleanup.clean(class_cleanup.mirah:92)
        at org.mirah.jvm.compiler.ScriptCleanup.enterClassDefinition(script_cleanup.mirah:119)
        at mirah.lang.ast.NodeScanner.visitClassDefinition(meta.mirah)
        at mirah.lang.ast.ClassDefinition.accept(klass.mirah)
        at mirah.lang.ast.NodeScanner.scan(meta.mirah)
        at mirah.lang.ast.NodeScanner.visitNodeList(meta.mirah)
        at mirah.lang.ast.NodeList.accept(lists.mirah)
        at mirah.lang.ast.NodeScanner.scan(meta.mirah)
        at mirah.lang.ast.NodeScanner.visitScript(meta.mirah)
        at mirah.lang.ast.Script.accept(structure.mirah)
        at org.mirah.jvm.compiler.Backend.clean(backend.mirah:64)
        at org.mirah.tool.MirahCompiler.compileAndLoadExtension(mirah_compiler.mirah:205)
        at org.mirah.macros.MacroBuilder.buildExtension(builder.mirah:112)
        at org.mirah.typer.Typer.visitMacroDefinition(typer.mirah:1267)
        at mirah.lang.ast.MacroDefinition.accept(intrinsics.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitNodeList(typer.mirah:828)
        at mirah.lang.ast.NodeList.accept(lists.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitClassDefinition(typer.mirah:478)
        at mirah.lang.ast.ClassDefinition.accept(klass.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)

        at org.mirah.typer.Typer.infer(typer.mirah:114)
        at org.mirah.typer.Typer.visitCast(typer.mirah:407)
        at mirah.lang.ast.Cast.accept(call.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.ProxyNode.inferChildren(proxy_node.mirah:129)
        at org.mirah.typer.Typer.visitFunctionalCall(typer.mirah:212)

        at mirah.lang.ast.FunctionalCall.accept(call.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitNodeList(typer.mirah:828)
        at mirah.lang.ast.NodeList.accept(lists.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.typer.Typer.visitScript(typer.mirah:848)
        at mirah.lang.ast.Script.accept(structure.mirah)
        at org.mirah.typer.Typer.infer(typer.mirah:120)
        at org.mirah.jvm.mirrors.SafeTyper.infer(safe_typer.mirah:48)
        at org.mirah.tool.MirahCompiler.infer(mirah_compiler.mirah:167)
        at org.mirah.tool.MirahTool.compile(mirah_tool.mirah:108)
        at org.mirah.tool.Mirahc.main(mirahc.mirah:34)

The empty lines highlight the difference between these stack traces.

Apparently, the Typer visits the ClassDefinition once when it is a parameter to the call of the "abstract" macro, and once when it is a return value to the call of the "abstract" macro.

felixvf pushed a commit to felixvf/mirah that referenced this issue Jun 22, 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