diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 1fc2c3d84..8d87218d4 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -205,6 +205,7 @@ public class TYPEStmt implements StatementVisitor{ @Override public void visit(BinaryExpr binary) { + if(binary.operation.equals(BinaryExpr.Operator.DIV) || binary.operation.equals(BinaryExpr.Operator.MUL)|| binary.operation.equals(BinaryExpr.Operator.MOD)|| @@ -216,9 +217,12 @@ public class TYPEStmt implements StatementVisitor{ //Expression muss zu Numeric Convertierbar sein. also von Numeric erben numeric.add(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT)); - //The type of a multiplicative expression is the promoted type of its operands. - numeric.add(new Pair(binary.rexpr.getType(), binary.getType(), PairOperator.SMALLERDOT)); - numeric.add(new Pair(binary.lexpr.getType(), binary.getType(), PairOperator.SMALLERDOT)); + /* + In Java passiert bei den binären Operatoren eine sogenannte Type Promotion: + https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2 + Das bedeutet, dass Java die Typen je nach belieben castet, so lange sie nur von Number erben + */ + numeric.add(new Pair(binary.getType(), number, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); if(binary.operation.equals(BinaryExpr.Operator.ADD)) { //Dann kann der Ausdruck auch das aneinanderfügen zweier Strings sein: ("a" + "b") oder (1 + 2) diff --git a/test/javFiles/AddLong.jav b/test/javFiles/AddLong.jav new file mode 100644 index 000000000..ceb31228e --- /dev/null +++ b/test/javFiles/AddLong.jav @@ -0,0 +1,9 @@ +import java.lang.Integer; +import java.lang.Long; + +public class AddLong{ + add(Integer a, Long b) { + Long c = a+b; + return c; + } +} \ No newline at end of file diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index bf48a5379..87551476d 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -72,6 +72,10 @@ public class JavaTXCompilerTest { public void expressions() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Expressions.jav")); } + @Test + public void addLong() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"AddLong.jav")); + } private static class TestResultSet{