mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
making InferredType easier to use
This commit is contained in:
parent
16ed68c1ec
commit
15a02d7664
@ -741,7 +741,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
|
|
||||||
override fun visit(array: ArrayLiteralValue) {
|
override fun visit(array: ArrayLiteralValue) {
|
||||||
if(array.type.isKnown) {
|
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)
|
errors.err("floating point used, but that is not enabled via options", array.position)
|
||||||
}
|
}
|
||||||
val arrayspec = ArrayIndex.forArray(array)
|
val arrayspec = ArrayIndex.forArray(array)
|
||||||
@ -1157,7 +1157,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
when {
|
when {
|
||||||
constvalue == null -> errors.err("choice value must be a constant", whenChoice.position)
|
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 !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 {
|
} else {
|
||||||
|
@ -15,6 +15,8 @@ object InferredTypes {
|
|||||||
fun getOrElse(transform: (InferredType) -> DataType): DataType =
|
fun getOrElse(transform: (InferredType) -> DataType): DataType =
|
||||||
if(isUnknown || isVoid) transform(this) else datatype!!
|
if(isUnknown || isVoid) transform(this) else datatype!!
|
||||||
infix fun istype(type: DataType): Boolean = if(isUnknown || isVoid) false else this.datatype==type
|
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 {
|
companion object {
|
||||||
fun unknown() = InferredType(isUnknown = true, isVoid = false, datatype = null)
|
fun unknown() = InferredType(isUnknown = true, isVoid = false, datatype = null)
|
||||||
|
@ -3,7 +3,9 @@ TODO
|
|||||||
|
|
||||||
For next compiler release
|
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
|
Blocked by Commander-x16 v39 release
|
||||||
|
Loading…
Reference in New Issue
Block a user