Skip to content

Commit c90d1e9

Browse files
committed
GROOVY-6438: @newify AST transformation doesn't work for anon inner classes
1 parent 149a11e commit c90d1e9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: src/main/org/codehaus/groovy/transform/NewifyASTTransformation.java

+5
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public Expression transform(Expression expr) {
169169
} else if (expr instanceof ClosureExpression) {
170170
ClosureExpression ce = (ClosureExpression) expr;
171171
ce.getCode().visit(this);
172+
} else if (expr instanceof ConstructorCallExpression) {
173+
ConstructorCallExpression cce = (ConstructorCallExpression) expr;
174+
if (cce.isUsingAnonymousInnerClass()) {
175+
cce.getType().visitContents(this);
176+
}
172177
} else if (expr instanceof DeclarationExpression) {
173178
DeclarationExpression de = (DeclarationExpression) expr;
174179
if (de == candidate || auto) {

Diff for: src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy

+10
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,14 @@ class NewifyTransformTest extends GroovyShellTestCase {
144144
assert t.toString() == 'Branch(Leaf(1), Branch(Branch(Leaf(2), Leaf(3)), Leaf(4)))'
145145
"""
146146
}
147+
148+
void testNewifyInnerClassNode_Groovy6438() {
149+
def test = evaluate '''
150+
@Newify String test() {
151+
new Object() { def x() { String.new('ABC') } }.x()
152+
}
153+
test()
154+
'''
155+
assert test == 'ABC'
156+
}
147157
}

0 commit comments

Comments
 (0)