fix compiler error about bool vs ubyte

This commit is contained in:
Irmen de Jong 2022-07-08 22:03:05 +02:00
parent 8acb37b6c2
commit d2d08bf143
2 changed files with 21 additions and 7 deletions

View File

@ -79,8 +79,18 @@ internal class AstChecker(private val program: Program,
errors.err("return value type mismatch or unknown symbol", returnStmt.value!!.position)
} else {
if (expectedReturnValues[0] != valueDt.getOr(DataType.UNDEFINED)) {
if(expectedReturnValues[0] != DataType.BOOL || valueDt.isnot(DataType.UBYTE))
if(valueDt istype DataType.BOOL && expectedReturnValues[0] == DataType.UBYTE) {
// if the return value is a bool and the return type is ubyte, allow this.
} else if(valueDt istype DataType.UBYTE && expectedReturnValues[0] == DataType.BOOL) {
// if the return value is ubyte and the return type is bool, allow this only if value is 0 or 1
val returnValue = returnStmt.value?.constValue(program)
if (returnValue == null || returnValue.type != DataType.UBYTE || (returnValue.number!=0.0 && returnValue.number!=1.0)) {
errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position)
}
}
else {
errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position)
}
}
}
}

View File

@ -4,14 +4,18 @@
main {
sub noCollision(ubyte xpos, ubyte ypos) -> bool {
if xpos
return false
else
return true
ubyte key
sub func() -> ubyte {
return key=='a'
}
sub func2() -> bool {
return key=='z'
}
sub start() {
bool z=noCollision(1,2)
bool @shared z1=func()
bool @shared z2=func2()
}
}