Skip to content

Commit 3080292

Browse files
committed
GROOVY-6851, GROOVY-9151, GROOVY-10104
1 parent f409522 commit 3080292

File tree

9 files changed

+1209
-4
lines changed

9 files changed

+1209
-4
lines changed

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

+43-3
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,26 @@ public void testCompileStatic6782() {
825825
runConformTest(sources);
826826
}
827827

828+
@Test
829+
public void testCompileStatic6851() {
830+
//@formatter:off
831+
String[] sources = {
832+
"Main.groovy",
833+
"@groovy.transform.CompileStatic\n" +
834+
"class Main {\n" +
835+
" static main(args) {\n" +
836+
" new Main().test()\n" +
837+
" }\n" +
838+
" void test(Map<String, Object> m = new HashMap<>(Collections.emptyMap())) {\n" +
839+
" print m\n" +
840+
" }\n" +
841+
"}\n",
842+
};
843+
//@formatter:on
844+
845+
runConformTest(sources, "[:]");
846+
}
847+
828848
@Test
829849
public void testCompileStatic6904() {
830850
//@formatter:off
@@ -4053,14 +4073,34 @@ public void testCompileStatic9151() {
40534073
runConformTest(sources, "hello world");
40544074
}
40554075

4056-
@Test @Ignore("https://issues.apache.org/jira/browse/GROOVY-9151")
4057-
public void testCompileStatic9151a() {
4076+
@Test
4077+
public void testCompileStatic9151and10104() {
4078+
//@formatter:off
4079+
String[] sources = {
4080+
"Main.groovy",
4081+
"@groovy.transform.CompileStatic\n" +
4082+
"void greet(Object o = 'world', String s = o.toString()) {\n" +
4083+
" print \"hello $s\"\n" +
4084+
"}\n" +
4085+
/*void greet() {
4086+
Object o = 'world'
4087+
greet(o, (String)o.toString()) // IncompatibleClassChangeError: Expected static method java.lang.Object.toString()Ljava/lang/String;
4088+
}*/
4089+
"greet()\n",
4090+
};
4091+
//@formatter:on
4092+
4093+
runConformTest(sources, "hello world");
4094+
}
4095+
4096+
@Test
4097+
public void testCompileStatic9151b() {
40584098
//@formatter:off
40594099
String[] sources = {
40604100
"Main.groovy",
40614101
"@groovy.transform.CompileStatic\n" +
40624102
"class Thing {\n" +
4063-
" Thing(Object o = 'foo', String s = o.toString()) {\n" +
4103+
" Thing(Object o = 'foo', String s = o) {\n" +
40644104
" print s\n" +
40654105
" }\n" +
40664106
"}\n" +

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ protected ClassNode[] getTypeCheckingAnnotations() {
126126
}
127127

128128
public static boolean isStaticallyCompiled(AnnotatedNode node) {
129-
if (node.getNodeMetaData(STATIC_COMPILE_NODE)!=null) return (Boolean)node.getNodeMetaData(STATIC_COMPILE_NODE);
129+
if (node.getNodeMetaData(STATIC_COMPILE_NODE) != null) {
130+
return Boolean.TRUE.equals(node.getNodeMetaData(STATIC_COMPILE_NODE));
131+
}
130132
if (node instanceof MethodNode) {
133+
// GRECLIPSE add -- GROOVY-6851, GROOVY-9151, GROOVY-10104
134+
if (!Boolean.TRUE.equals(node.getNodeMetaData(org.codehaus.groovy.classgen.Verifier.DEFAULT_PARAMETER_GENERATED)))
135+
// GRECLIPSE end
131136
return isStaticallyCompiled(node.getDeclaringClass());
132137
}
133138
if (node instanceof InnerClassNode) {

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

+3
Original file line numberDiff line numberDiff line change
@@ -3076,11 +3076,13 @@ public void visitConstructor(final ConstructorNode node) {
30763076
// method has already been visited by a static type checking visitor
30773077
return;
30783078
}
3079+
/* GRECLIPSE edit -- GROOVY-6851, GROOVY-9151, GROOVY-10104
30793080
for (Parameter parameter : node.getParameters()) {
30803081
if (parameter.getInitialExpression() != null) {
30813082
parameter.getInitialExpression().visit(this);
30823083
}
30833084
}
3085+
*/
30843086
super.visitConstructor(node);
30853087
}
30863088

@@ -3106,6 +3108,7 @@ protected void startMethodInference(final MethodNode node, ErrorCollector collec
31063108
try {
31073109
typeCheckingContext.isInStaticContext = node.isStatic();
31083110
super.visitMethod(node);
3111+
/* GRECLIPSE edit -- GROOVY-6851, GROOVY-9151, GROOVY-10104
31093112
for (Parameter parameter : node.getParameters()) {
31103113
if (parameter.getInitialExpression() != null) {
31113114
parameter.getInitialExpression().visit(this);

base/org.codehaus.groovy30/.checkstyle

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<file-match-pattern match-pattern="groovy/transform/DelegateASTTransformation.java" include-pattern="false" />
6969
<file-match-pattern match-pattern="groovy/transform/FieldASTTransformation.java" include-pattern="false" />
7070
<file-match-pattern match-pattern="groovy/transform/LogASTTransformation.java" include-pattern="false" />
71+
<file-match-pattern match-pattern="groovy/transform/sc/StaticCompilationVisitor.java" include-pattern="false" />
7172
<file-match-pattern match-pattern="groovy/transform/sc/transformers/(Binary|MethodCall)ExpressionTransformer.java" include-pattern="false" />
7273
<file-match-pattern match-pattern="groovy/transform/stc/AbstractExtensionMethodCache.java" include-pattern="false" />
7374
<file-match-pattern match-pattern="groovy/transform/stc/StaticTypeCheckingSupport.java" include-pattern="false" />

0 commit comments

Comments
 (0)