diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index 927fafb7c..3eeef4c64 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -376,6 +376,9 @@ internal class AstChecker(private val program: Program, if (sourceVar?.struct != null) { if (sourceVar.struct !== targetVar.struct) errors.err("assignment of different struct types", assignment.position) + } else if(sourceVar?.isArray==true) { + if((sourceVar.value as ArrayLiteralValue).value.size != targetVar.struct?.numberOfElements) + errors.err("number of elements doesn't match struct definition", sourceVar.position) } } } diff --git a/compiler/src/prog8/ast/processing/StatementReorderer.kt b/compiler/src/prog8/ast/processing/StatementReorderer.kt index 4546c1f26..5d0af0cb4 100644 --- a/compiler/src/prog8/ast/processing/StatementReorderer.kt +++ b/compiler/src/prog8/ast/processing/StatementReorderer.kt @@ -187,6 +187,8 @@ internal class StatementReorderer(val program: Program) : AstWalker() { // structs are not the same in assignment return listOf() // error will be printed elsewhere } + if(struct.statements.size!=sourceStruct.statements.size) + return listOf() // error will be printed elsewhere return struct.statements.zip(sourceStruct.statements).map { member -> val targetDecl = member.first as VarDecl val sourceDecl = member.second as VarDecl @@ -203,6 +205,8 @@ internal class StatementReorderer(val program: Program) : AstWalker() { } sourceVar.isArray -> { val array = (sourceVar.value as ArrayLiteralValue).value + if(struct.statements.size!=array.size) + return listOf() // error will be printed elsewhere return struct.statements.zip(array).map { val decl = it.first as VarDecl val mangled = mangledStructMemberName(identifierName, decl.name)