slightly less strict

This commit is contained in:
Irmen de Jong 2024-02-20 23:01:51 +01:00
parent 0e17a0474a
commit 96b5a30f60
2 changed files with 8 additions and 33 deletions

View File

@ -1058,12 +1058,12 @@ internal class AstChecker(private val program: Program,
} 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))
if(rightDt.largerThan(origLeftDt) && !(expr.right as NumericLiteral).cast(origLeftDt).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).istype(DataType.FLOAT)) {
val origRightDt = (expr.right as TypecastExpression).expression.inferType(program).getOr(DataType.UNDEFINED)
if(!origRightDt.equalsSize(leftDt))
if(leftDt.largerThan(origRightDt) && !(expr.left as NumericLiteral).cast(origRightDt).isValid)
errors.err("operands are not the same type", expr.right.position)
}
}

View File

@ -5,40 +5,15 @@
main {
sub start() {
ubyte[256] @shared arr1 = 99
ubyte[256] @shared arr2 = 0
uword[128] @shared warr1 = 9999
uword[128] @shared warr2 = 0
ubyte @shared pointer
const uword value = 255
txt.print_ub(all(arr2))
txt.nl()
txt.print_ub(all(warr2))
txt.nl()
arr2 = arr1
warr2 = warr1
txt.print_ub(all(arr2))
txt.nl()
txt.print_ub(all(warr2))
txt.nl()
uword[] @split cave_times = [1111,2222,3333,4444]
cave_times = [9999,8888,7777,6666]
for cx16.r0L in 0 to len(cave_times)-1 {
txt.print_uw(cave_times[cx16.r0L])
txt.spc()
if pointer>value {
cx16.r0L++
}
txt.nl()
ubyte[] cave_times2 = [11,22,33,44]
cave_times2 = [99,88,77,66]
for cx16.r0L in 0 to len(cave_times2)-1 {
txt.print_ub(cave_times2[cx16.r0L])
txt.spc()
if pointer>50000 {
cx16.r0L++
}
txt.nl()
}
}