mirror of
https://github.com/irmen/prog8.git
synced 2025-08-15 14:27:37 +00:00
added type check to catch invalid comparisons, fix maze example
This commit is contained in:
@@ -1055,6 +1055,17 @@ internal class AstChecker(private val program: Program,
|
|||||||
// str+str and str*number have already been const evaluated before we get here.
|
// str+str and str*number have already been const evaluated before we get here.
|
||||||
errors.err("no computational or logical expressions with strings or arrays are possible", expr.position)
|
errors.err("no computational or logical expressions with strings or arrays are possible", expr.position)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if(expr.left is TypecastExpression && expr.right is NumericLiteral && !expr.right.inferType(program).istype(DataType.FLOAT)) {
|
||||||
|
val origLeftDt = (expr.left as TypecastExpression).expression.inferType(program).getOr(DataType.UNDEFINED)
|
||||||
|
if(!origLeftDt.equalsSize(rightDt))
|
||||||
|
errors.err("operands are not the same type", expr.right.position)
|
||||||
|
}
|
||||||
|
if(expr.right is TypecastExpression && expr.left is NumericLiteral && !expr.left.inferType(program).istype(DataType.FLOAT)) {
|
||||||
|
val origRightDt = (expr.right as TypecastExpression).expression.inferType(program).getOr(DataType.UNDEFINED)
|
||||||
|
if(!origRightDt.equalsSize(leftDt))
|
||||||
|
errors.err("operands are not the same type", expr.right.position)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(leftDt==DataType.BOOL || rightDt==DataType.BOOL ||
|
if(leftDt==DataType.BOOL || rightDt==DataType.BOOL ||
|
||||||
|
@@ -267,7 +267,7 @@ solve_loop:
|
|||||||
else {
|
else {
|
||||||
; dead end, pop stack
|
; dead end, pop stack
|
||||||
pathstackptr--
|
pathstackptr--
|
||||||
if stackptr==65535 {
|
if pathstackptr==65535 {
|
||||||
txt.print("no solution?!")
|
txt.print("no solution?!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user