Skip to content

Commit c3b4b08

Browse files
committed
GROOVY-9857
1 parent 878d269 commit c3b4b08

File tree

9 files changed

+2479
-22
lines changed

9 files changed

+2479
-22
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BuildAccessRulesTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2020 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,10 +89,10 @@ public void testAccessForImport() {
8989
@Test
9090
public void testAccessForExtends() {
9191
String source = "import java.beans.*\n" +
92-
"class Foo extends BeanDescriptor {\n" +
92+
"class Foo extends SimpleBeanInfo {\n" +
9393
"}";
9494

95-
assertAccessRestriction(source, "BeanDescriptor");
95+
assertAccessRestriction(source, "SimpleBeanInfo");
9696
}
9797

9898
@Test

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GenericsTests.java

+3
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ public void testCallingGenericConstructors() {
454454
"p/B.groovy",
455455
"package p\n" +
456456
"class B extends A {\n" +
457+
" B() {\n" +
458+
" super(42)\n" +
459+
" }\n" +
457460
" void m() {\n" +
458461
" new A(42)\n" +
459462
" }\n" +

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java

+21
Original file line numberDiff line numberDiff line change
@@ -5558,6 +5558,27 @@ public void testGroovy9391() {
55585558
"----------\n");
55595559
}
55605560

5561+
@Test // https://issues.apache.org/jira/browse/GROOVY-9857
5562+
public void testGroovy9857() {
5563+
//@formatter:off
5564+
String[] sources = {
5565+
"Main.groovy",
5566+
"abstract class A {\n" +
5567+
" A(boolean b) { }\n" +
5568+
"}\n" +
5569+
"class C extends A {}\n",
5570+
};
5571+
//@formatter:on
5572+
5573+
runNegativeTest(sources,
5574+
"----------\n" +
5575+
"1. ERROR in Main.groovy (at line 4)\n" +
5576+
"\tclass C extends A {}\n" +
5577+
"\t ^\n" +
5578+
"Groovy:Implicit super constructor A() is undefined for generated constructor. Must define an explicit constructor.\n" +
5579+
"----------\n");
5580+
}
5581+
55615582
@Test // https://issues.apache.org/jira/browse/GROOVY-9906
55625583
public void testGroovy9906() {
55635584
//@formatter:off

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

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2021 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
package org.eclipse.jdt.groovy.core.tests.xform;
1717

1818
import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isAtLeastGroovy;
19+
import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isParrotParser;
1920
import static org.junit.Assume.assumeTrue;
2021

2122
import org.eclipse.jdt.groovy.core.tests.basic.GroovyCompilerTestSuite;
@@ -40,7 +41,8 @@ public void testRecordType1() {
4041
"import static java.lang.reflect.Modifier.isFinal\n" +
4142
"assert isFinal(Simple.class.modifiers)\n" +
4243
"def obj = new Simple(1,'x')\n" +
43-
"print obj.n\n" +
44+
"print obj.n()\n" +
45+
"print obj.s\n" +
4446
"print obj\n",
4547

4648
"Simple.groovy",
@@ -52,6 +54,29 @@ public void testRecordType1() {
5254
};
5355
//@formatter:on
5456

55-
runConformTest(sources, "1Simple[n=1, s=x]");
57+
runConformTest(sources, "1xSimple[n=1, s=x]");
58+
}
59+
60+
@Test
61+
public void testRecordType2() {
62+
assumeTrue(isParrotParser());
63+
64+
//@formatter:off
65+
String[] sources = {
66+
"Script.groovy",
67+
"import static java.lang.reflect.Modifier.isFinal\n" +
68+
"assert isFinal(Simple.class.modifiers)\n" +
69+
"def obj = new Simple(1,'x')\n" +
70+
"print obj.n()\n" +
71+
"print obj.s\n" +
72+
"print obj\n",
73+
74+
"Simple.groovy",
75+
"record Simple(Integer n, String s) {\n" +
76+
"}\n",
77+
};
78+
//@formatter:on
79+
80+
runConformTest(sources, "1xSimple[n=1, s=x]");
5681
}
5782
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/AsmClassGenerator.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,23 @@ private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[]
494494
}
495495
}
496496
if (!hasCallToSuper) {
497-
// GRECLIPSE add -- GROOVY-9373
497+
// GRECLIPSE add -- GROOVY-9373, GROOVY-9857
498498
if (code != null) {
499499
int line = code.getLineNumber();
500500
if (line > 0) {
501501
mv.visitLineNumber(line, l0);
502502
controller.setLineNumber(line);
503503
}
504504
}
505+
if (controller.getClassNode().getSuperClass().getDeclaredConstructor(Parameter.EMPTY_ARRAY) == null) { ASTNode where = node;
506+
String error = "Implicit super constructor " + controller.getClassNode().getSuperClass().getNameWithoutPackage() + "() is undefined";
507+
if (node.getLineNumber() > 0) error += ". Must explicitly invoke another constructor.";
508+
else {
509+
error += " for generated constructor. Must define an explicit constructor.";
510+
where = controller.getClassNode();
511+
}
512+
addError(error, where);
513+
}
505514
// GRECLIPSE end
506515
// add call to "super()"
507516
mv.visitVarInsn(ALOAD, 0);

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/AsmClassGenerator.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,23 @@ private void visitStdMethod(final MethodNode node, final boolean isConstructor,
453453
}
454454
}
455455
if (!hasCallToSuper) {
456-
// GRECLIPSE add -- GROOVY-9373
456+
// GRECLIPSE add -- GROOVY-9373, GROOVY-9857
457457
if (code != null) {
458458
int line = code.getLineNumber();
459459
if (line > 0) {
460460
mv.visitLineNumber(line, l0);
461461
controller.setLineNumber(line);
462462
}
463463
}
464+
if (controller.getClassNode().getSuperClass().getDeclaredConstructor(Parameter.EMPTY_ARRAY) == null) { ASTNode where = node;
465+
String error = "Implicit super constructor " + controller.getClassNode().getSuperClass().getNameWithoutPackage() + "() is undefined";
466+
if (node.getLineNumber() > 0) error += ". Must explicitly invoke another constructor.";
467+
else {
468+
error += " for generated constructor. Must define an explicit constructor.";
469+
where = controller.getClassNode();
470+
}
471+
addError(error, where);
472+
}
464473
// GRECLIPSE end
465474
// add call to "super()"
466475
mv.visitVarInsn(ALOAD, 0);

base/org.codehaus.groovy40/.checkstyle

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<file-match-pattern match-pattern="groovy/ast/expr/(Static)?MethodCallExpression.java" include-pattern="false" />
3636
<file-match-pattern match-pattern="groovy/ast/tools/(Expression|Generics)Utils.java" include-pattern="false" />
3737
<file-match-pattern match-pattern="groovy/classgen/(Annotation|Enum)Visitor.java" include-pattern="false" />
38+
<file-match-pattern match-pattern="groovy/classgen/AsmClassGenerator.java" include-pattern="false" />
3839
<file-match-pattern match-pattern="groovy/classgen/(Extended)?Verifier.java" include-pattern="false" />
3940
<file-match-pattern match-pattern="groovy/classgen/GeneratorContext.java" include-pattern="false" />
4041
<file-match-pattern match-pattern="groovy/classgen/asm/WriterController.java" include-pattern="false" />

0 commit comments

Comments
 (0)