diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 43bd7245c..ae1ede7d1 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -451,6 +451,10 @@ internal class AstChecker(private val program: Program, errors.err("typecasting a float value in-place makes no sense", assignment.value.position) } + val numvalue = assignment.value.constValue(program) + if(numvalue!=null && targetDt.isKnown) + checkValueTypeAndRange(targetDt.getOr(DataType.UNDEFINED), numvalue) + super.visit(assignment) } diff --git a/compiler/test/TestNumbers.kt b/compiler/test/TestNumbers.kt index 5fb92bc0f..1b5334476 100644 --- a/compiler/test/TestNumbers.kt +++ b/compiler/test/TestNumbers.kt @@ -145,11 +145,40 @@ class TestNumbers: FunSpec({ } } """ - val errors = ErrorReporterForTests(keepMessagesAfterReporting = true) + val errors = ErrorReporterForTests() compileText(C64Target, true, src, writeAssembly = false, errors=errors).assertFailure() errors.errors.size shouldBe 2 errors.warnings.size shouldBe 0 errors.errors[0] shouldContain "converted to float" errors.errors[1] shouldContain "converted to float" } + + test("out of range number assignments") { + val src=""" + main { + sub start() { + uword @shared qq = ${'$'}2ff33 + cx16.r0 = ${'$'}1fc0f + } + } + """ + val errors = ErrorReporterForTests() + compileText(C64Target, true, src, writeAssembly = false, errors=errors).assertFailure() + errors.errors.size shouldBe 2 + errors.warnings.size shouldBe 0 + errors.errors[0] shouldContain "out of range" + errors.errors[1] shouldContain "out of range" + } + + test("big numbers okay in const expressions if result fits") { + val src=""" + main { + sub start() { + uword @shared qq = ${'$'}2ff33 >> 4 + cx16.r0 = ${'$'}1fc0f >> 4 + } + } + """ + compileText(C64Target, true, src, writeAssembly = false).assertSuccess() + } }) diff --git a/compiler/test/TestOptimization.kt b/compiler/test/TestOptimization.kt index f41748019..cb910445d 100644 --- a/compiler/test/TestOptimization.kt +++ b/compiler/test/TestOptimization.kt @@ -573,8 +573,9 @@ class TestOptimization: FunSpec({ """ val errors = ErrorReporterForTests() compileText(C64Target, optimize=true, src, writeAssembly=false, errors = errors).assertFailure() - errors.errors.size shouldBe 1 + errors.errors.size shouldBe 2 errors.errors[0] shouldContain "type of value BYTE doesn't match target UBYTE" + errors.errors[1] shouldContain "out of range" } test("test augmented expression asmgen") { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index e0bcbd2f0..c70b607b1 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- FIx: cx16.r0 = $1fc0f compiler crash - Fix: uword addr = label ; addr will be 0! required to use &label! - Fix compiler stack overflow crash: sub sprite_y_for_row(ubyte row) -> word { diff --git a/examples/test.p8 b/examples/test.p8 index 5896a9d49..cb9f40973 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,22 +3,7 @@ main { sub start() { - move() - } - - sub move() { - ubyte mb = cx16.mouse_pos() - ubyte @shared xx = cx16.r0H - ubyte @shared yy = cx16.r0L - func(cx16.r0H) - func(cx16.r0L) - cx16.vpoke(1, $fc08+2, cx16.r0H) - cx16.vpoke(1, $fc08+3, cx16.r0L) - } - - asmsub func(ubyte qq @A) { - %asm {{ - rts - }} + uword @shared qq = $2ff33 + cx16.r0 = $1fc0f } }