prog8 icon indicating copy to clipboard operation
prog8 copied to clipboard

compiler crash when using call builtin

Open djehuti opened this issue 9 months ago • 5 comments

The following PR exhibits the issue. When building the target repo with this PR:

* internal error *
Exception in thread "main" kotlin.UninitializedPropertyAccessException: lateinit property parent has not been initialized
        at prog8.code.ast.PtNode.getParent(AstBase.kt:15)
        at prog8.code.ast.PtNode.definingBlock(AstBase.kt:129)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:59)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols(AsmGen.kt:98)
        at prog8.codegen.cpu6502.AsmGen6502.generate(AsmGen.kt:27)
        at prog8.compiler.CompilerKt.createAssemblyAndAssemble(Compiler.kt:496)
        at prog8.compiler.CompilerKt.compileProgram(Compiler.kt:147)
        at prog8.CompilerMainKt.compileMain(CompilerMain.kt:262)
        at prog8.CompilerMainKt.main(CompilerMain.kt:28)
make: *** [Makefile:30: hworld.prg] Error 1

djehuti avatar Apr 30 '24 14:04 djehuti

I think I know, what could cause it?

void = call(workFunc)

technically, the correct syntax for ignoring a return value from a single return value function is this:

void call(workFunc)

void = syntax wasn't a thing until multi-return syntax was added recently, and I guess the handling of void = for regular functions wasn't added, so stuff happen.

But that's just my thesis.

adiee5 avatar Apr 30 '24 17:04 adiee5

Yup, that fixes it. That's a fine workaround for me! (I'm used to that syntax.)

djehuti avatar Apr 30 '24 18:04 djehuti

I'll let you ( @irmen ) decide whether to keep this open to handle that or just close it.

djehuti avatar Apr 30 '24 18:04 djehuti

yeah, let desertfish see it, so he can add a proper error message

adiee5 avatar Apr 30 '24 18:04 adiee5

With -target virtual, it also crashes, but with a different error

Exception in thread "main" java.lang.IllegalArgumentException: node prog8.code.ast.PtFunctionCall@ccd1bc3 name is not scoped: call at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:65) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:79) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:79) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:79) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping(IRCodeGen.kt:90) at prog8.codegen.intermediate.IRCodeGen.generate(IRCodeGen.kt:26)

irmen avatar May 02 '24 19:05 irmen

Minimal reproduction:

main {
  sub start() {
    void = call($2000)
  }
}

related compiler crash:

main {
  sub start() {
    void = 123
  }
}

irmen avatar May 18 '24 14:05 irmen