Skip to content
Merged
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 @@ -2392,6 +2392,9 @@ protected void restoreVariableExpressionMetadata(final Map<VariableExpression, M
if (typesBeforeVisit != null) {
for (Map.Entry<VariableExpression, Map<StaticTypesMarker, Object>> entry : typesBeforeVisit.entrySet()) {
for (StaticTypesMarker marker : StaticTypesMarker.values()) {
// GROOVY-9344, GROOVY-9516
if (marker == INFERRED_TYPE) continue;

Object value = entry.getValue().get(marker);
if (value == null) {
entry.getKey().removeNodeMetaData(marker);
Expand Down
18 changes: 17 additions & 1 deletion src/test/groovy/transform/stc/ClosuresSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,23 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
def x = '123';
{ -> x = 123 }
x.charAt(0) // available in String but not available in Integer
''', 'A closure shared variable [x] has been assigned with various types and the method [charAt(int)] does not exist in the lowest upper bound'
''', 'Cannot find matching method java.io.Serializable or java.lang.Comparable'
}

// GROOVY-9516
void testClosureSharedVariable3() {
shouldFailWithMessages '''
class A {}
class B extends A { def m() {} }
class C extends A {}

void test() {
def x = new B();
{ -> x = new C() }();
def c = x
c.m()
}
''', 'Cannot find matching method A#m()'
}

void testClosureCallAsAMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.codehaus.groovy.classgen.asm.sc

import groovy.test.NotYetImplemented
import groovy.transform.CompileStatic
import org.junit.Test

Expand Down Expand Up @@ -51,31 +50,31 @@ final class StaticCompileFlowTypingTest {

@groovy.transform.CompileStatic
String m() {
def var = new A()
def x = new A()
def c = { ->
var = new B()
var.class.simpleName
x = new B()
x.class.simpleName
}
c()
}
assert m() == 'B'
'''
}

@NotYetImplemented @Test // GROOVY-9344
@Test // GROOVY-9344
void testFlowTyping3() {
assertScript '''
class A {}
class B {}

@groovy.transform.CompileStatic
String m() {
def var = new A()
def x = new A()
def c = { ->
var = new B()
x = new B()
}
c()
var.class.simpleName
x.class.simpleName
}
assert m() == 'B'
'''
Expand Down