diff --git a/compiler/src/prog8/compiler/astprocessing/BoolRemover.kt b/compiler/src/prog8/compiler/astprocessing/BoolRemover.kt index 30df7e7b5..a85ca8019 100644 --- a/compiler/src/prog8/compiler/astprocessing/BoolRemover.kt +++ b/compiler/src/prog8/compiler/astprocessing/BoolRemover.kt @@ -2,6 +2,7 @@ package prog8.compiler.astprocessing import prog8.ast.Node import prog8.ast.Program +import prog8.ast.base.FatalAstException import prog8.ast.expressions.* import prog8.ast.statements.Subroutine import prog8.ast.statements.SubroutineParameter @@ -14,7 +15,8 @@ internal class BoolRemover(val program: Program) : AstWalker() { override fun before(typecast: TypecastExpression, parent: Node): Iterable { if(typecast.type == DataType.BOOL) { - val notZero = BinaryExpression(typecast.expression, "!=", NumericLiteral(DataType.UBYTE, 0.0, typecast.position), typecast.position) + val valueDt = typecast.expression.inferType(program).getOrElse { throw FatalAstException("unknown dt") } + val notZero = BinaryExpression(typecast.expression, "!=", NumericLiteral(valueDt, 0.0, typecast.position), typecast.position) return listOf(IAstModification.ReplaceNode(typecast, notZero, parent)) } return noModifications diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 5819f2aa1..bb39f23f1 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,10 +3,11 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- make sure bool value is always 0 or 1 (all casts should convert), then: - - rewrite bool=bool^1 into bool=not bool +- make sure bool value is always 0 or 1 (all casts should convert, or actually, bool!=0 comparison should return 0 or 1), then: + - ast rewrite bool=bool^1 into bool=not bool - should solve: bool bb = not bb -> larger code than bool bb ^= 1 +- check that bool==0 / bool==1 / bool!=0 / bool != 1 are optimized away ...