Skip to content

Commit

Permalink
[457779] no basic type should be assignable to boolean
Browse files Browse the repository at this point in the history
https://bugs.eclipse.org/bugs/show_bug.cgi?id=457779

Change-Id: Icea9838ac651cdb1efb3046fb27b0875e380290b
Signed-off-by: Lorenzo Bettini <lorenzo.bettini@gmail.com>
  • Loading branch information
LorenzoBettini authored and Sebastian Zarnekow committed Jan 21, 2015
1 parent e55b1d6 commit c377b73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -1099,7 +1099,8 @@ private int internalGetPrimitiveKindFromWrapper(JvmTypeParameter type, /* @Nulla
private boolean isWideningConversion(int leftPrimitiveKind, int rightPrimitiveKind) {
switch (rightPrimitiveKind) {
case PRIMITIVE_BYTE :
switch (leftPrimitiveKind) {
switch (leftPrimitiveKind) {
case PRIMITIVE_BOOLEAN:
case PRIMITIVE_VOID:
case PRIMITIVE_BYTE:
return false;
Expand All @@ -1109,6 +1110,7 @@ private boolean isWideningConversion(int leftPrimitiveKind, int rightPrimitiveKi
case PRIMITIVE_SHORT :
case PRIMITIVE_CHAR :
switch (leftPrimitiveKind) {
case PRIMITIVE_BOOLEAN:
case PRIMITIVE_VOID:
case PRIMITIVE_BYTE:
case PRIMITIVE_SHORT:
Expand Down
Expand Up @@ -395,6 +395,28 @@ public void testEntrySetAdd_02() throws Exception {
helper.assertError(xExpression, XbasePackage.Literals.XFEATURE_CALL, UNREACHABLE_CODE, "Unreachable code.");
}

@Test public void testByteCannotBeAssignedToBoolean() throws Exception {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=457779
assertConformanceError("boolean", "byte");
}

@Test public void testShortCannotBeAssignedToBoolean() throws Exception {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=457779
assertConformanceError("boolean", "char");
}

@Test public void testCharCannotBeAssignedToBoolean() throws Exception {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=457779
assertConformanceError("boolean", "char");
}

protected void assertConformanceError(String leftType, String rightType)
throws Exception {
final XExpression xExpression = expression(
"{var " + leftType + " left; var " + rightType + " right; left = right;}", false);
helper.assertError(xExpression, XbasePackage.Literals.XFEATURE_CALL, INCOMPATIBLE_TYPES, "Cannot", rightType, leftType);
}

protected void assertConformanceError(String expression, EClass objectType, String... messageParts)
throws Exception {
final XExpression xExpression = expression(expression, false);
Expand Down

0 comments on commit c377b73

Please sign in to comment.