Skip to content

Commit 3f377f3

Browse files
committed
GROOVY-10109
1 parent 270c534 commit 3f377f3

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -7286,6 +7286,26 @@ public void testCompileStatic10089() {
72867286
runConformTest(sources, "[[id:x, name:null, count:1]]");
72877287
}
72887288

7289+
@Test
7290+
public void testCompileStatic10109() {
7291+
//@formatter:off
7292+
String[] sources = {
7293+
"Main.groovy",
7294+
"@groovy.transform.CompileStatic\n" +
7295+
"String test(String string) {\n" +
7296+
" new StringBuilder().with {\n" +
7297+
" int len = length()\n" + // IllegalAccessError
7298+
" append(string)\n" +
7299+
" toString()\n" +
7300+
" }\n" +
7301+
"}\n" +
7302+
"print test('works')\n",
7303+
};
7304+
//@formatter:on
7305+
7306+
runConformTest(sources, "works");
7307+
}
7308+
72897309
@Test
72907310
public void testCompileStatic10197() {
72917311
for (String override : new String[] {"int getBaz() {1}", "final int baz = 1"}) {

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -1274,13 +1274,11 @@ private static ClassNode makeRawType(final ClassNode receiver) {
12741274
return raw;
12751275
}
12761276

1277-
private static Collection<MethodNode> removeCovariantsAndInterfaceEquivalents(final Collection<MethodNode> collection) {
1278-
List<MethodNode> toBeRemoved = new ArrayList<>();
1279-
List<MethodNode> list = new ArrayList<>(new LinkedHashSet<>(collection));
1277+
private static List<MethodNode> removeCovariantsAndInterfaceEquivalents(final Collection<MethodNode> collection) {
1278+
List<MethodNode> list = new ArrayList<>(new LinkedHashSet<>(collection)), toBeRemoved = new ArrayList<>();
12801279
for (int i = 0, n = list.size(); i < n - 1; i += 1) {
12811280
MethodNode one = list.get(i);
1282-
if (toBeRemoved.contains(one)) continue;
1283-
for (int j = i + 1; j < list.size(); j++) {
1281+
for (int j = i + 1; j < n && !toBeRemoved.contains(one); j += 1) {
12841282
MethodNode two = list.get(j);
12851283
if (toBeRemoved.contains(two)) continue;
12861284
if (one.getParameters().length == two.getParameters().length) {
@@ -1307,11 +1305,10 @@ private static Collection<MethodNode> removeCovariantsAndInterfaceEquivalents(fi
13071305
} else if (!oneDC.equals(twoDC)) {
13081306
if (ParameterUtils.parametersEqual(one.getParameters(), two.getParameters())) {
13091307
// GROOVY-6882, GROOVY-6970: drop overridden or interface equivalent method
1310-
// GROOVY-8638, GROOVY-10120: unless bridge method (synthetic variant) overrides
13111308
if (twoDC.isInterface() ? oneDC.implementsInterface(twoDC) : oneDC.isDerivedFrom(twoDC)) {
1312-
toBeRemoved.add(isSynthetic(one, two) ? one : two);
1309+
toBeRemoved.add(two);
13131310
} else if (oneDC.isInterface() ? twoDC.isInterface() : twoDC.isDerivedFrom(oneDC)) {
1314-
toBeRemoved.add(isSynthetic(two, one) ? two : one);
1311+
toBeRemoved.add(one);
13151312
}
13161313
}
13171314
}

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -1205,12 +1205,10 @@ private static ClassNode makeRawType(final ClassNode receiver) {
12051205
}
12061206

12071207
private static List<MethodNode> removeCovariantsAndInterfaceEquivalents(final Collection<MethodNode> collection) {
1208-
List<MethodNode> toBeRemoved = new ArrayList<>();
1209-
List<MethodNode> list = new ArrayList<>(new LinkedHashSet<>(collection));
1208+
List<MethodNode> list = new ArrayList<>(new LinkedHashSet<>(collection)), toBeRemoved = new ArrayList<>();
12101209
for (int i = 0, n = list.size(); i < n - 1; i += 1) {
12111210
MethodNode one = list.get(i);
1212-
if (toBeRemoved.contains(one)) continue;
1213-
for (int j = i + 1; j < n; j += 1) {
1211+
for (int j = i + 1; j < n && !toBeRemoved.contains(one); j += 1) {
12141212
MethodNode two = list.get(j);
12151213
if (toBeRemoved.contains(two)) continue;
12161214
if (one.getParameters().length == two.getParameters().length) {
@@ -1237,11 +1235,10 @@ private static List<MethodNode> removeCovariantsAndInterfaceEquivalents(final Co
12371235
} else if (!oneDC.equals(twoDC)) {
12381236
if (ParameterUtils.parametersEqual(one.getParameters(), two.getParameters())) {
12391237
// GROOVY-6882, GROOVY-6970: drop overridden or interface equivalent method
1240-
// GROOVY-8638, GROOVY-10120: unless bridge method (synthetic variant) overrides
12411238
if (twoDC.isInterface() ? oneDC.implementsInterface(twoDC) : oneDC.isDerivedFrom(twoDC)) {
1242-
toBeRemoved.add(isSynthetic(one, two) ? one : two);
1239+
toBeRemoved.add(two);
12431240
} else if (oneDC.isInterface() ? twoDC.isInterface() : twoDC.isDerivedFrom(oneDC)) {
1244-
toBeRemoved.add(isSynthetic(two, one) ? two : one);
1241+
toBeRemoved.add(one);
12451242
}
12461243
}
12471244
}

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,7 @@ private static List<MethodNode> removeCovariantsAndInterfaceEquivalents(final Co
12021202
List<MethodNode> list = new ArrayList<>(new LinkedHashSet<>(collection)), toBeRemoved = new ArrayList<>();
12031203
for (int i = 0, n = list.size(); i < n - 1; i += 1) {
12041204
MethodNode one = list.get(i);
1205-
if (toBeRemoved.contains(one)) continue;
1206-
for (int j = i + 1; j < n; j += 1) {
1205+
for (int j = i + 1; j < n && !toBeRemoved.contains(one); j += 1) {
12071206
MethodNode two = list.get(j);
12081207
if (toBeRemoved.contains(two)) continue;
12091208
if (one.getParameters().length == two.getParameters().length) {
@@ -1230,11 +1229,10 @@ private static List<MethodNode> removeCovariantsAndInterfaceEquivalents(final Co
12301229
} else if (!oneDC.equals(twoDC)) {
12311230
if (ParameterUtils.parametersEqual(one.getParameters(), two.getParameters())) {
12321231
// GROOVY-6882, GROOVY-6970: drop overridden or interface equivalent method
1233-
// GROOVY-8638, GROOVY-10120: unless bridge method (synthetic variant) overrides
12341232
if (twoDC.isInterface() ? oneDC.implementsInterface(twoDC) : oneDC.isDerivedFrom(twoDC)) {
1235-
toBeRemoved.add(isSynthetic(one, two) ? one : two);
1233+
toBeRemoved.add(two);
12361234
} else if (oneDC.isInterface() ? (disjoint ? twoDC.implementsInterface(oneDC) : twoDC.isInterface()) : twoDC.isDerivedFrom(oneDC)) {
1237-
toBeRemoved.add(isSynthetic(two, one) ? two : one);
1235+
toBeRemoved.add(one);
12381236
}
12391237
}
12401238
}

0 commit comments

Comments
 (0)