mirror of
https://github.com/irmen/prog8.git
synced 2024-12-27 05:29:38 +00:00
fix compiler error about bool vs ubyte
This commit is contained in:
parent
8acb37b6c2
commit
d2d08bf143
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user