Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ private boolean tryImplicitReceiver(final Expression origin, final Expression me

rewritten.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, origin.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE));
} else {
makeCall(origin, pexp, message, arguments, adapter, safe, spreadSafe, false);
// the receiver is no longer this, so a call without a target must not be made on the current object
makeCall(origin, pexp, message, arguments, adapter == invokeMethodOnCurrent ? invokeMethod : adapter, safe, spreadSafe, false);
}
return true;
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/groovy/groovy/transform/stc/ClosuresSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,24 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
'''
}

// GROOVY-12581
@Test
void testClosureDelegateInInstanceInitializer() {
assertScript '''
class C {
List<String> log = [];
{
log << new StringBuilder('a').with { append('b') }.toString()
log << new ArrayList<String>().tap { add('c') }.toString()
log << new ArrayList<String>(['d']).with { get(0) }
log << new StringBuilder('e').with { length().toString() }
}
}

assert new C().log == ['ab', '[c]', 'd', '1']
'''
}

// GROOVY-9604
@Test
void testClosureResolveStrategy() {
Expand Down
Loading