diff --git a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt index 97a5d1599..d9c32d969 100644 --- a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt +++ b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt @@ -463,14 +463,16 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val override fun after(whenChoice: WhenChoice, parent: Node): Iterable { val conditionDt = (whenChoice.parent as When).condition.inferType(program) - val values = whenChoice.values - values?.toTypedArray()?.withIndex()?.forEach { (index, value) -> - val valueDt = value.inferType(program) - if(valueDt!=conditionDt) { - val castedValue = value.typecastTo(conditionDt.getOr(DataType.UNDEFINED), valueDt.getOr(DataType.UNDEFINED), true) - if(castedValue.first) { - castedValue.second.linkParents(whenChoice) - values[index] = castedValue.second + if(conditionDt.isKnown) { + val values = whenChoice.values + values?.toTypedArray()?.withIndex()?.forEach { (index, value) -> + val valueDt = value.inferType(program) + if(valueDt!=conditionDt) { + val castedValue = value.typecastTo(conditionDt.getOr(DataType.UNDEFINED), valueDt.getOr(DataType.UNDEFINED), true) + if(castedValue.first) { + castedValue.second.linkParents(whenChoice) + values[index] = castedValue.second + } } } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 8d3b14f5b..e546d5831 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -chess fails to compile (crash) - remove redundant assignments in calls like this where the result registers are the same as the assigment targets: void, cx16.r0s, cx16.r1s = cx16.mouse_pos() (6502 + IR) diff --git a/examples/test.p8 b/examples/test.p8 index aed1ac724..1f0785d0a 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,6 +4,16 @@ main { sub start() { - void, cx16.r0s, cx16.r1s = cx16.mouse_pos() + cx16.mouse_config2(1) + wait_mousebutton() + + sub wait_mousebutton() { + do { + cx16.r0L, void, void = cx16.mouse_pos() + } until cx16.r0L!=0 + do { + cx16.r0L, void, void = cx16.mouse_pos() + } until cx16.r0L==0 + } } }