mirror of
https://github.com/irmen/prog8.git
synced 2025-11-02 13:16:07 +00:00
allow comparisons against constant values with different type
This commit is contained in:
@@ -1276,17 +1276,6 @@ internal class AstChecker(private val program: Program,
|
||||
// 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)
|
||||
}
|
||||
} else {
|
||||
if(expr.left is TypecastExpression && expr.right is NumericLiteral && !(expr.right.inferType(program) issimpletype BaseDataType.FLOAT)) {
|
||||
val origLeftDt = (expr.left as TypecastExpression).expression.inferType(program).getOrUndef()
|
||||
if(rightDt.largerSizeThan(origLeftDt) && !(expr.right as NumericLiteral).cast(origLeftDt.base, true).isValid)
|
||||
errors.err("operands are not the same type", expr.right.position)
|
||||
}
|
||||
if(expr.right is TypecastExpression && expr.left is NumericLiteral && !(expr.left.inferType(program) issimpletype BaseDataType.FLOAT)) {
|
||||
val origRightDt = (expr.right as TypecastExpression).expression.inferType(program).getOrUndef()
|
||||
if(leftDt.largerSizeThan(origRightDt) && !(expr.left as NumericLiteral).cast(origRightDt.base, true).isValid)
|
||||
errors.err("operands are not the same type", expr.right.position)
|
||||
}
|
||||
}
|
||||
|
||||
if(leftDt.isBool || rightDt.isBool ||
|
||||
|
||||
@@ -954,4 +954,17 @@ main {
|
||||
(v4.right as NumericLiteral).type shouldBe BaseDataType.UWORD
|
||||
(v4.right as NumericLiteral).number shouldBe 5
|
||||
}
|
||||
|
||||
test("allow comparisons against constant values with different type") {
|
||||
val src = """
|
||||
main {
|
||||
sub start() {
|
||||
const uword MAX_CAVE_WIDTH = 440 ; word here to avoid having to cast to word all the time
|
||||
|
||||
if cx16.r0L > MAX_CAVE_WIDTH
|
||||
return
|
||||
}
|
||||
}"""
|
||||
compileText(C64Target(), false, src, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user