From fda8e61be4d403bfef969fece069bc33ae180658 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 20 May 2024 21:51:07 +0200 Subject: [PATCH] give better error when using @split wrong --- .../src/prog8/compiler/astprocessing/AstChecker.kt | 5 +++++ compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt | 2 +- .../src/prog8/ast/statements/AstStatements.kt | 5 ----- examples/test.p8 | 12 +++++++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index a64fafd51..00864ad81 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -844,6 +844,11 @@ internal class AstChecker(private val program: Program, if(compilerOptions.zeropage==ZeropageType.DONTUSE && decl.zeropage == ZeropageWish.REQUIRE_ZEROPAGE) err("zeropage usage has been disabled by options") + if(decl.splitArray) { + if (decl.datatype !in arrayOf(DataType.ARRAY_W, DataType.ARRAY_UW, DataType.ARRAY_W_SPLIT, DataType.ARRAY_UW_SPLIT)) { + errors.err("split can only be used on word arrays", decl.position) + } + } super.visit(decl) } diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index 6a6fad4b9..4c1da62cc 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -688,7 +688,7 @@ private fun VardeclContext.toAst(type: VarDeclType, value: Expression?): VarDecl when(arrayDt) { DataType.ARRAY_UW -> DataType.ARRAY_UW_SPLIT DataType.ARRAY_W -> DataType.ARRAY_W_SPLIT - else -> throw SyntaxError("split can only be used on word arrays", toPosition()) + else -> arrayDt // type error will be generated later in the ast check } } else arrayDt } else origDt diff --git a/compilerAst/src/prog8/ast/statements/AstStatements.kt b/compilerAst/src/prog8/ast/statements/AstStatements.kt index bc24696e6..67a0cd84f 100644 --- a/compilerAst/src/prog8/ast/statements/AstStatements.kt +++ b/compilerAst/src/prog8/ast/statements/AstStatements.kt @@ -231,11 +231,6 @@ class VarDecl(val type: VarDeclType, override lateinit var parent: Node var allowInitializeWithZero = true - init { - if(splitArray) - require(datatype in ArrayDatatypes) { "array dt mismatch" } - } - companion object { private var autoHeapValueSequenceNumber = 0 diff --git a/examples/test.p8 b/examples/test.p8 index ba4cd7983..2b320ed56 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -2,8 +2,14 @@ main { sub start() { - repeat cx16.r0 { - cx16.r1L++ - } + bool @split bb + ubyte @split bt + byte[200] @split ba + float @split fl + float[10] @split fla + + bb=true + bt++ + fl++ } }