error message for invalid operand types for logical or bitwise operators

This commit is contained in:
Irmen de Jong 2019-01-31 21:38:45 +01:00
parent 255c808b16
commit 8e36a64d49
5 changed files with 15 additions and 3 deletions

View File

@ -65,4 +65,4 @@ task fatJar(type: Jar) {
from { project.configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
build.finalizedBy(fatJar)
// build.finalizedBy(fatJar)

View File

@ -694,6 +694,13 @@ private class AstChecker(private val namespace: INameScope,
checkResult.add(ExpressionError("remainder can only be used on unsigned integer operands", expr.right.position))
}
}
"and", "or", "xor", "&", "|", "^" -> {
// only integer numeric operands accepted
val rightDt = expr.right?.resultingDatatype(namespace, heap)
val leftDt = expr.left.resultingDatatype(namespace, heap)
if(leftDt !in IntegerDatatypes || rightDt !in IntegerDatatypes)
checkResult.add(ExpressionError("logical or bitwise operator can only be used on integer operands", expr.right.position))
}
}
val leftDt = expr.left.resultingDatatype(namespace, heap)!!

View File

@ -1,4 +1,4 @@
// Generated from prog8.g4 by ANTLR 4.7.2
// Generated from ./parser/antlr/prog8.g4 by ANTLR 4.7.2
package prog8.parser;

View File

@ -1,4 +1,4 @@
// Generated from prog8.g4 by ANTLR 4.7.2
// Generated from ./parser/antlr/prog8.g4 by ANTLR 4.7.2
package prog8.parser;

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="prog8" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python">
<configuration sdkName="Python 3.7" />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">