You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2023/05/01 17:15:20 UTC
[groovy] branch master updated: GROOVY-11036: `getAllInterfaces()` cycle check
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new ba1e5010fa GROOVY-11036: `getAllInterfaces()` cycle check
ba1e5010fa is described below
commit ba1e5010fa12713868a3507a107695549e4e0046
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon May 1 11:26:54 2023 -0500
GROOVY-11036: `getAllInterfaces()` cycle check
---
.../java/org/codehaus/groovy/ast/ClassNode.java | 8 +++---
src/test/groovy/bugs/Groovy3904.groovy | 30 +++++++++++++---------
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index 945eacf7ac..dbb847e354 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -457,17 +457,15 @@ public class ClassNode extends AnnotatedNode {
public Set<ClassNode> getAllInterfaces() {
Set<ClassNode> result = new LinkedHashSet<>();
+ if (isInterface()) result.add(this);
getAllInterfaces(result);
return result;
}
private void getAllInterfaces(Set<ClassNode> set) {
- if (isInterface()) {
- set.add(this);
- }
for (ClassNode face : getInterfaces()) {
- set.add(face);
- face.getAllInterfaces(set);
+ if (set.add(face)) // GROOVY-11036
+ face.getAllInterfaces(set);
}
}
diff --git a/src/test/groovy/bugs/Groovy3904.groovy b/src/test/groovy/bugs/Groovy3904.groovy
index 419d2f0c02..0da5f08b95 100644
--- a/src/test/groovy/bugs/Groovy3904.groovy
+++ b/src/test/groovy/bugs/Groovy3904.groovy
@@ -30,27 +30,25 @@ final class Groovy3904 {
}
@Test
- void testCyclicInheritenceTC1() {
+ void testCyclicInheritence1() {
compileAndVerifyCyclicInheritenceCompilationError '''
class G3904R1A extends G3904R1A {}
'''
}
@Test
- void testCyclicInheritenceTC2() {
+ void testCyclicInheritence2() {
compileAndVerifyCyclicInheritenceCompilationError '''
class G3904R2A extends G3904R2A {
- public static void main(String []argv) {
- print 'hey'
+ static main(args) {
+ print 'hello'
}
}
'''
}
- /* next 2 tests are similar but in reverse order */
-
@Test
- void testCyclicInheritenceTC3() {
+ void testCyclicInheritence3() {
compileAndVerifyCyclicInheritenceCompilationError '''
class G3904R3A extends G3904R3B {}
class G3904R3B extends G3904R3A {}
@@ -58,15 +56,15 @@ final class Groovy3904 {
}
@Test
- void testCyclicInheritenceTC4() {
+ void testCyclicInheritence4() {
compileAndVerifyCyclicInheritenceCompilationError '''
class G3904R4B extends G3904R4A {}
class G3904R4A extends G3904R4B {}
'''
}
- @Test // cyclic inheritence is between 2 parent classes
- void testCyclicInheritenceTC5() {
+ @Test
+ void testCyclicInheritence5() {
compileAndVerifyCyclicInheritenceCompilationError '''
class G3904R5A extends G3904R5B {}
class G3904R5B extends G3904R5C {}
@@ -74,8 +72,8 @@ final class Groovy3904 {
'''
}
- @Test // cyclic inheritence is between 2 parent classes with a normal level in-between
- void testCyclicInheritenceTC6() {
+ @Test
+ void testCyclicInheritence6() {
compileAndVerifyCyclicInheritenceCompilationError '''
class G3904R6A extends G3904R6B {}
class G3904R6B extends G3904R6C {}
@@ -83,4 +81,12 @@ final class Groovy3904 {
class G3904R6D extends G3904R6B {}
'''
}
+
+ @Test // GROOVY-11036
+ void testCyclicInheritence7() {
+ compileAndVerifyCyclicInheritenceCompilationError '''
+ interface I11036 {}
+ interface J11036 extends J11036, I11036 {}
+ '''
+ }
}