Skip to content

Commit

Permalink
GROOVY-6851, GROOVY-9151, GROOVY-10104
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 24, 2021
1 parent f409522 commit 3080292
Show file tree
Hide file tree
Showing 9 changed files with 1,209 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,26 @@ public void testCompileStatic6782() {
runConformTest(sources);
}

@Test
public void testCompileStatic6851() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class Main {\n" +
" static main(args) {\n" +
" new Main().test()\n" +
" }\n" +
" void test(Map<String, Object> m = new HashMap<>(Collections.emptyMap())) {\n" +
" print m\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "[:]");
}

@Test
public void testCompileStatic6904() {
//@formatter:off
Expand Down Expand Up @@ -4053,14 +4073,34 @@ public void testCompileStatic9151() {
runConformTest(sources, "hello world");
}

@Test @Ignore("https://issues.apache.org/jira/browse/GROOVY-9151")
public void testCompileStatic9151a() {
@Test
public void testCompileStatic9151and10104() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"void greet(Object o = 'world', String s = o.toString()) {\n" +
" print \"hello $s\"\n" +
"}\n" +
/*void greet() {
Object o = 'world'
greet(o, (String)o.toString()) // IncompatibleClassChangeError: Expected static method java.lang.Object.toString()Ljava/lang/String;
}*/
"greet()\n",
};
//@formatter:on

runConformTest(sources, "hello world");
}

@Test
public void testCompileStatic9151b() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class Thing {\n" +
" Thing(Object o = 'foo', String s = o.toString()) {\n" +
" Thing(Object o = 'foo', String s = o) {\n" +
" print s\n" +
" }\n" +
"}\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ protected ClassNode[] getTypeCheckingAnnotations() {
}

public static boolean isStaticallyCompiled(AnnotatedNode node) {
if (node.getNodeMetaData(STATIC_COMPILE_NODE)!=null) return (Boolean)node.getNodeMetaData(STATIC_COMPILE_NODE);
if (node.getNodeMetaData(STATIC_COMPILE_NODE) != null) {
return Boolean.TRUE.equals(node.getNodeMetaData(STATIC_COMPILE_NODE));
}
if (node instanceof MethodNode) {
// GRECLIPSE add -- GROOVY-6851, GROOVY-9151, GROOVY-10104
if (!Boolean.TRUE.equals(node.getNodeMetaData(org.codehaus.groovy.classgen.Verifier.DEFAULT_PARAMETER_GENERATED)))
// GRECLIPSE end
return isStaticallyCompiled(node.getDeclaringClass());
}
if (node instanceof InnerClassNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3076,11 +3076,13 @@ public void visitConstructor(final ConstructorNode node) {
// method has already been visited by a static type checking visitor
return;
}
/* GRECLIPSE edit -- GROOVY-6851, GROOVY-9151, GROOVY-10104
for (Parameter parameter : node.getParameters()) {
if (parameter.getInitialExpression() != null) {
parameter.getInitialExpression().visit(this);
}
}
*/
super.visitConstructor(node);
}

Expand All @@ -3106,6 +3108,7 @@ protected void startMethodInference(final MethodNode node, ErrorCollector collec
try {
typeCheckingContext.isInStaticContext = node.isStatic();
super.visitMethod(node);
/* GRECLIPSE edit -- GROOVY-6851, GROOVY-9151, GROOVY-10104
for (Parameter parameter : node.getParameters()) {
if (parameter.getInitialExpression() != null) {
parameter.getInitialExpression().visit(this);
Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy30/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<file-match-pattern match-pattern="groovy/transform/DelegateASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/FieldASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/LogASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/StaticCompilationVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/transformers/(Binary|MethodCall)ExpressionTransformer.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/stc/AbstractExtensionMethodCache.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/stc/StaticTypeCheckingSupport.java" include-pattern="false" />
Expand Down
Loading

0 comments on commit 3080292

Please sign in to comment.