Skip to content

Commit 4665fa1

Browse files
committed
GROOVY-10239
1 parent c1c4fef commit 4665fa1

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+58
Original file line numberDiff line numberDiff line change
@@ -3280,4 +3280,62 @@ public void testTypeChecked10217() {
32803280

32813281
runConformTest(sources, "11");
32823282
}
3283+
3284+
@Test
3285+
public void testTypeChecked10239() {
3286+
assumeTrue(isParrotParser());
3287+
3288+
//@formatter:off
3289+
String[] sources = {
3290+
"Main.groovy",
3291+
"@groovy.transform.TypeChecked\n" +
3292+
"void test(List<C> list) {\n" +
3293+
" def result = list.findAll {\n" +
3294+
" it.e !in [E.X]\n" + // Cannot cast object 'true' with class 'java.lang.Boolean' to class 'Enum10239'
3295+
" }\n" +
3296+
" print result.size()\n" +
3297+
"}\n" +
3298+
"test([new C(E.X), new C(E.Y), new C(null)])\n",
3299+
3300+
"Types.groovy",
3301+
"@groovy.transform.TupleConstructor(defaults=false)\n" +
3302+
"class C {\n" +
3303+
" E e\n" +
3304+
"}\n" +
3305+
"enum E {\n" +
3306+
" X, Y\n" +
3307+
"}\n",
3308+
};
3309+
//@formatter:on
3310+
3311+
runConformTest(sources, "2");
3312+
}
3313+
3314+
@Test
3315+
public void testTypeChecked10239a() {
3316+
//@formatter:off
3317+
String[] sources = {
3318+
"Main.groovy",
3319+
"@groovy.transform.TypeChecked\n" +
3320+
"void test(List<C> list) {\n" +
3321+
" def result = list.findAll {\n" +
3322+
" !(it.e in [E.X])\n" +
3323+
" }\n" +
3324+
" print result.size()\n" +
3325+
"}\n" +
3326+
"test([new C(E.X), new C(E.Y), new C(null)])\n",
3327+
3328+
"Types.groovy",
3329+
"@groovy.transform.TupleConstructor(defaults=false)\n" +
3330+
"class C {\n" +
3331+
" E e\n" +
3332+
"}\n" +
3333+
"enum E {\n" +
3334+
" X, Y\n" +
3335+
"}\n",
3336+
};
3337+
//@formatter:on
3338+
3339+
runConformTest(sources, "2");
3340+
}
32833341
}

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+3
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,9 @@ public void visitBinaryExpression(final BinaryExpression expression) {
797797
? getResultType(rType, op, lType, reversedBinaryExpression)
798798
: getResultType(lType, op, rType, expression);
799799
if (op == KEYWORD_IN || op == COMPARE_NOT_IN) {
800+
// GRECLIPSE add -- GROOVY-10239
801+
if (resultType == null) resultType = boolean_TYPE;
802+
// GRECLIPSE end
800803
// in case of the "in" operator, the receiver and the arguments are reversed
801804
// so we use the reversedExpression and get the target method from it
802805
storeTargetMethod(expression, reversedBinaryExpression.getNodeMetaData(DIRECT_METHOD_CALL_TARGET));

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+1
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ public void visitBinaryExpression(final BinaryExpression expression) {
807807
// for the "in" or "!in" operator, the receiver and the arguments are reversed
808808
BinaryExpression reverseExpression = binX(rightExpression, expression.getOperation(), leftExpression);
809809
resultType = getResultType(rType, op, lType, reverseExpression);
810+
if (resultType == null) resultType = boolean_TYPE; // GROOVY-10239
810811
storeTargetMethod(expression, reverseExpression.getNodeMetaData(DIRECT_METHOD_CALL_TARGET));
811812
} else {
812813
resultType = getResultType(lType, op, rType, expression);

0 commit comments

Comments
 (0)