mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
fixed possible type mismatch error in when statements
This commit is contained in:
parent
6938c79f88
commit
7c219d235c
@ -404,17 +404,35 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun after(whenChoice: WhenChoice, parent: Node): Iterable<IAstModification> {
|
override fun after(whenChoice: WhenChoice, parent: Node): Iterable<IAstModification> {
|
||||||
|
val conditionDt = (whenChoice.parent as When).condition.inferType(program)
|
||||||
if((parent as When).condition.inferType(program).isWords) {
|
if((parent as When).condition.inferType(program).isWords) {
|
||||||
val values = whenChoice.values
|
val values = whenChoice.values
|
||||||
values?.toTypedArray()?.withIndex()?.forEach { (index, value) ->
|
values?.toTypedArray()?.withIndex()?.forEach { (index, value) ->
|
||||||
val num = value.constValue(program)
|
val valueDt = value.inferType(program)
|
||||||
if(num!=null && num.type in ByteDatatypes) {
|
if(valueDt!=conditionDt) {
|
||||||
val wordNum = NumericLiteral(if(num.type==DataType.UBYTE) DataType.UWORD else DataType.WORD, num.number, num.position)
|
val castedValue = (value as NumericLiteral).cast(conditionDt.getOr(DataType.UNDEFINED))
|
||||||
wordNum.parent = num.parent
|
if(castedValue.isValid) {
|
||||||
values[index] = wordNum
|
values[index] = castedValue.valueOrZero()
|
||||||
|
} else {
|
||||||
|
errors.err("choice value datatype differs from condition value", value.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
val values = whenChoice.values
|
||||||
|
values?.toTypedArray()?.withIndex()?.forEach { (index, value) ->
|
||||||
|
val valueDt = value.inferType(program)
|
||||||
|
if(valueDt!=conditionDt) {
|
||||||
|
val castedValue = (value as NumericLiteral).cast(conditionDt.getOr(DataType.UNDEFINED))
|
||||||
|
if(castedValue.isValid) {
|
||||||
|
values[index] = castedValue.valueOrZero()
|
||||||
|
} else {
|
||||||
|
errors.err("choice value datatype differs from condition value", value.position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- IR: optimize WHEN codegen? translate(whenStmt: PtWhen)
|
|
||||||
- IR: instructions that do type conversion (SZ etc, CONCAT, SGN) should put the result in a DIFFERENT register.
|
- IR: instructions that do type conversion (SZ etc, CONCAT, SGN) should put the result in a DIFFERENT register.
|
||||||
- IR: reduce the number of branch instructions (gradually), replace with CMP(I) + status branch instruction
|
- IR: reduce the number of branch instructions (gradually), replace with CMP(I) + status branch instruction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user