You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/03/14 04:09:55 UTC
[groovy] branch GROOVY-9449 created (now 55101fe)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch GROOVY-9449
in repository https://gitbox.apache.org/repos/asf/groovy.git.
at 55101fe GROOVY-9449: Mutliple methods with the same name now fail before AST transformations can fix it
This branch includes the following new commits:
new 55101fe GROOVY-9449: Mutliple methods with the same name now fail before AST transformations can fix it
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[groovy] 01/01: GROOVY-9449: Mutliple methods with the same name
now fail before AST transformations can fix it
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9449
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 55101fe903029aceed95694a94124412fbb77de1
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Mar 14 12:09:44 2020 +0800
GROOVY-9449: Mutliple methods with the same name now fail before AST transformations can fix it
---
.../org/apache/groovy/parser/antlr4/AstBuilder.java | 17 ++---------------
.../apache/groovy/parser/antlr4/GroovyParserTest.groovy | 4 ++++
.../apache/groovy/parser/antlr4/SyntaxErrorTest.groovy | 1 -
.../BUG-GROOVY-9449.groovy} | 14 ++++++++------
4 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 69904f2..b366212 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1649,7 +1649,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
}
private MethodNode createMethodNodeForClass(MethodDeclarationContext ctx, ModifierManager modifierManager, String methodName, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code, ClassNode classNode, int modifiers) {
- MethodNode methodNode;
if (asBoolean(ctx.elementValue())) { // the code of annotation method
code = configureAST(
new ExpressionStatement(
@@ -1659,25 +1658,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
}
modifiers |= !modifierManager.containsAny(STATIC) && (classNode.isInterface() || (isTrue(classNode, IS_INTERFACE_WITH_DEFAULT_METHODS) && !modifierManager.containsAny(DEFAULT))) ? Opcodes.ACC_ABSTRACT : 0;
-
- checkWhetherMethodNodeWithSameSignatureExists(classNode, methodName, parameters, ctx);
-
- methodNode = classNode.addMethod(methodName, modifiers, returnType, parameters, exceptions, code);
+ MethodNode methodNode = new MethodNode(methodName, modifiers, returnType, parameters, exceptions, code);
+ classNode.addMethod(methodNode);
methodNode.setAnnotationDefault(asBoolean(ctx.elementValue()));
return methodNode;
}
- private void checkWhetherMethodNodeWithSameSignatureExists(ClassNode classNode, String methodName, Parameter[] parameters, MethodDeclarationContext ctx) {
- MethodNode sameSigMethodNode = classNode.getDeclaredMethod(methodName, parameters);
-
- if (null == sameSigMethodNode) {
- return;
- }
-
- throw createParsingFailedException("The method " + sameSigMethodNode.getText() + " duplicates another method of the same signature", ctx);
- }
-
private ConstructorNode createConstructorNodeForClass(String methodName, Parameter[] parameters, ClassNode[] exceptions, Statement code, ClassNode classNode, int modifiers) {
ConstructorCallExpression thisOrSuperConstructorCallExpression = this.checkThisAndSuperConstructorCall(code);
if (asBoolean(thisOrSuperConstructorCallExpression)) {
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index b64e18a..a32b079 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -446,4 +446,8 @@ final class GroovyParserTest extends GroovyTestCase {
void "test groovy core - GROOVY-9433"() {
doTest('bugs/BUG-GROOVY-9433.groovy');
}
+
+ void "test groovy core - GROOVY-9449"() {
+ doTest('bugs/BUG-GROOVY-9449.groovy');
+ }
}
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index fc7cebd..ce37a69 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -144,7 +144,6 @@ final class SyntaxErrorTest extends GroovyTestCase {
}
void "test groovy core - ClassDeclaration"() {
- TestUtils.doRunAndShouldFail('fail/ClassDeclaration_01x.groovy')
TestUtils.doRunAndShouldFail('fail/ClassDeclaration_02x.groovy')
}
diff --git a/subprojects/parser-antlr4/src/test/resources/fail/ClassDeclaration_01x.groovy b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-9449.groovy
similarity index 87%
rename from subprojects/parser-antlr4/src/test/resources/fail/ClassDeclaration_01x.groovy
rename to subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-9449.groovy
index b60a794..ce897b7 100644
--- a/subprojects/parser-antlr4/src/test/resources/fail/ClassDeclaration_01x.groovy
+++ b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-9449.groovy
@@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package fail
+class Foo extends Specification {
+ def foo() {
+ expect: true
+ }
-class A {
- String foo() {}
- def foo() {}
-}
-new A()
\ No newline at end of file
+ def foo() {
+ expect: false
+ }
+}
\ No newline at end of file