diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 511ba12a3..7d8ac6040 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -741,7 +741,7 @@ internal class AstChecker(private val program: Program, override fun visit(array: ArrayLiteralValue) { if(array.type.isKnown) { - if (!compilerOptions.floats && array.type.getOr(DataType.UNDEFINED) in setOf(DataType.FLOAT, DataType.ARRAY_F)) { + if (!compilerOptions.floats && array.type.oneOf(DataType.FLOAT, DataType.ARRAY_F)) { errors.err("floating point used, but that is not enabled via options", array.position) } val arrayspec = ArrayIndex.forArray(array) @@ -1157,7 +1157,7 @@ internal class AstChecker(private val program: Program, when { constvalue == null -> errors.err("choice value must be a constant", whenChoice.position) constvalue.type !in IntegerDatatypes -> errors.err("choice value must be a byte or word", whenChoice.position) - constvalue.type != conditionType.getOr(DataType.UNDEFINED) -> errors.err("choice value datatype differs from condition value", whenChoice.position) + !conditionType.istype(constvalue.type) -> errors.err("choice value datatype differs from condition value", whenChoice.position) } } } else { diff --git a/compilerAst/src/prog8/ast/expressions/InferredTypes.kt b/compilerAst/src/prog8/ast/expressions/InferredTypes.kt index 857c273f6..55dd6eea6 100644 --- a/compilerAst/src/prog8/ast/expressions/InferredTypes.kt +++ b/compilerAst/src/prog8/ast/expressions/InferredTypes.kt @@ -15,6 +15,8 @@ object InferredTypes { fun getOrElse(transform: (InferredType) -> DataType): DataType = if(isUnknown || isVoid) transform(this) else datatype!! infix fun istype(type: DataType): Boolean = if(isUnknown || isVoid) false else this.datatype==type + infix fun isnot(type: DataType): Boolean = if(isUnknown || isVoid) true else this.datatype!=type + fun oneOf(vararg types: DataType) = if(isUnknown || isVoid) false else this.datatype in types companion object { fun unknown() = InferredType(isUnknown = true, isVoid = false, datatype = null) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 04237514a..af51107a8 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,9 @@ TODO For next compiler release ^^^^^^^^^^^^^^^^^^^^^^^^^ -... +replace uses of inferredType.istype(..) by infix form +replace checks against multiple types with .oneOf(...) +replace certain uses of inferredType.getOr(UNKNOWN) by i.getOrElse({ errorhandler }) Blocked by Commander-x16 v39 release