From 8e36a64d496fcf1baaa6ede63877e9a45d415fc9 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 31 Jan 2019 21:38:45 +0100 Subject: [PATCH] error message for invalid operand types for logical or bitwise operators --- compiler/build.gradle | 2 +- compiler/src/prog8/ast/AstChecker.kt | 7 +++++++ parser/src/prog8/parser/prog8Lexer.java | 2 +- parser/src/prog8/parser/prog8Parser.java | 2 +- prog8.iml | 5 +++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/build.gradle b/compiler/build.gradle index f03d6b8bb..0cd13ca77 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -65,4 +65,4 @@ task fatJar(type: Jar) { from { project.configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } with jar } -build.finalizedBy(fatJar) \ No newline at end of file +// build.finalizedBy(fatJar) \ No newline at end of file diff --git a/compiler/src/prog8/ast/AstChecker.kt b/compiler/src/prog8/ast/AstChecker.kt index 83985e87f..5fe0bf326 100644 --- a/compiler/src/prog8/ast/AstChecker.kt +++ b/compiler/src/prog8/ast/AstChecker.kt @@ -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)!! diff --git a/parser/src/prog8/parser/prog8Lexer.java b/parser/src/prog8/parser/prog8Lexer.java index 0b8da28a9..47f66e372 100644 --- a/parser/src/prog8/parser/prog8Lexer.java +++ b/parser/src/prog8/parser/prog8Lexer.java @@ -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; diff --git a/parser/src/prog8/parser/prog8Parser.java b/parser/src/prog8/parser/prog8Parser.java index 1ab6baa85..5e1c76b65 100644 --- a/parser/src/prog8/parser/prog8Parser.java +++ b/parser/src/prog8/parser/prog8Parser.java @@ -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; diff --git a/prog8.iml b/prog8.iml index a3d1f940e..e187d18c5 100644 --- a/prog8.iml +++ b/prog8.iml @@ -1,5 +1,10 @@ + + + + +