diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 38e980505..7337b90fb 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -509,7 +509,7 @@ internal class AstChecker(private val program: Program, val sourceDatatype = assignment.value.inferType(program) if (sourceDatatype.isUnknown) { if (assignment.value !is FunctionCallExpression) - errors.err("assignment value is invalid or has no proper datatype, maybe forgot '&' (address-of)", assignment.value.position) + errors.err("invalid assignment value, maybe forgot '&' (address-of)", assignment.value.position) } else { checkAssignmentCompatible(targetDatatype.getOr(DataType.UNDEFINED), sourceDatatype.getOr(DataType.UNDEFINED), assignment.value) @@ -843,8 +843,15 @@ internal class AstChecker(private val program: Program, val leftIDt = expr.left.inferType(program) val rightIDt = expr.right.inferType(program) - if(!leftIDt.isKnown || !rightIDt.isKnown) + if(!leftIDt.isKnown || !rightIDt.isKnown) { + // check if maybe one of the operands is a label, this would need a '&' + if (!leftIDt.isKnown && expr.left !is FunctionCallExpression) + errors.err("invalid operand, maybe forgot '&' (address-of)", expr.left.position) + if (!rightIDt.isKnown && expr.right !is FunctionCallExpression) + errors.err("invalid operand, maybe forgot '&' (address-of)", expr.right.position) + return // hopefully this error will be detected elsewhere + } val leftDt = leftIDt.getOr(DataType.UNDEFINED) val rightDt = rightIDt.getOr(DataType.UNDEFINED) diff --git a/compiler/test/TestAstChecks.kt b/compiler/test/TestAstChecks.kt index c3e602bf1..bbc3c8eb7 100644 --- a/compiler/test/TestAstChecks.kt +++ b/compiler/test/TestAstChecks.kt @@ -52,8 +52,8 @@ class TestAstChecks: FunSpec({ compileText(C64Target(), true, text, writeAssembly = true, errors=errors) shouldBe null errors.errors.size shouldBe 2 errors.warnings.size shouldBe 0 - errors.errors[0] shouldContain ":7:28: assignment value is invalid" - errors.errors[1] shouldContain ":8:28: assignment value is invalid" + errors.errors[0] shouldContain ":7:28: invalid assignment value, maybe forgot '&'" + errors.errors[1] shouldContain ":8:28: invalid assignment value, maybe forgot '&'" } test("can't do str or array expression without using address-of") {