Jelajahi Sumber

fixed bug #874: Type inferrer validation of ternary operations produces false issues

terfloth@itemis.de 12 tahun lalu
induk
melakukan
ea19693436

+ 2 - 2
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/types/STextDefaultTypeSystem.java

@@ -504,8 +504,8 @@ public class STextDefaultTypeSystem extends AbstractTypeSystem implements
 						IStatus.ERROR));
 			}
 			// compute a union of the second and third operand types
-			InferenceResult unionResult = union(firstOperandType,
-					secondOperandType);
+			InferenceResult unionResult = union(secondOperandType,
+					thirdOperandType);
 			unionResult.getIssues().addAll(issues);
 			return unionResult;
 		default:

+ 10 - 0
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/TypeInferrerTest.java

@@ -865,6 +865,16 @@ public class TypeInferrerTest extends AbstractSTextTest {
 		assertTrue(isStringType(inferType("( 'abc' )")));
 	}
 
+	
+	@Test
+	public void testTernaryExpression() {
+		assertTrue(isIntegerType(inferType("(1<2) ? 4 : 5")));
+		assertTrue(isBooleanType(inferType("(true) ? false : true")));
+		
+		expectIssue(inferType("(true) ? 4 : false"), "Cannot compute a type union for the given types: integer, boolean");
+	}
+
+	
 	protected InferenceResult inferType(String expression) {
 		return inferType(expression, super.internalScope(),
 				super.interfaceScope());