From f1193bb5a0c2483847943ac373b00ee824f4d0d3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 22 Aug 2020 23:13:53 +0200 Subject: [PATCH] Better error message --- compiler/src/prog8/ast/processing/AstChecker.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index 08a712efa..f9e5a1919 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -304,7 +304,6 @@ internal class AstChecker(private val program: Program, } else { // Pass-by-reference datatypes can not occur as parameters to a subroutine directly // Instead, their reference (address) should be passed (as an UWORD). - // TODO The language has no (typed) pointers at this time. Should this be handled better? if(subroutine.parameters.any{it.type in PassByReferenceDatatypes }) { err("Pass-by-reference types (str, array) cannot occur as a parameter type directly. Instead, use an uword to receive their address, or access the variable from the outer scope directly.") } @@ -361,8 +360,12 @@ internal class AstChecker(private val program: Program, } val targetDt = assignment.target.inferType(program, assignment) - if(assignment.value.inferType(program) != targetDt) - errors.err("assignment value is of different type as the target", assignment.value.position) + if(assignment.value.inferType(program) != targetDt) { + if(targetDt.typeOrElse(DataType.STRUCT) in IterableDatatypes) + errors.err("cannot assign value to string or array", assignment.value.position) + else + errors.err("value's type doesn't match target", assignment.value.position) + } if(assignment.value is TypecastExpression) { if(assignment.isAugmentable && targetDt.istype(DataType.FLOAT))