GROOVY-11370: add test case
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 9e03d1e..f7a546c 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1708,7 +1708,7 @@
foundGetterOrSetter = (foundGetterOrSetter || getter != null || !setters.isEmpty());
}
- // GROOVY-5568: the property may be defined by DGM
+ // GROOVY-5568, GROOVY-9115, GROOVY-9123: the property may be defined by an extension
for (ClassNode dgmReceiver : isPrimitiveType(receiverType) ? new ClassNode[]{receiverType, getWrapper(receiverType)} : new ClassNode[]{receiverType}) {
Set<MethodNode> methods = findDGMMethodsForClassNode(getSourceUnit().getClassLoader(), dgmReceiver, getterName);
for (MethodNode method : findDGMMethodsForClassNode(getSourceUnit().getClassLoader(), dgmReceiver, isserName)) {
diff --git a/src/test/groovy/bugs/Groovy9115.groovy b/src/test/groovy/bugs/Groovy9115.groovy
index 748327d..900e931 100644
--- a/src/test/groovy/bugs/Groovy9115.groovy
+++ b/src/test/groovy/bugs/Groovy9115.groovy
@@ -18,49 +18,47 @@
*/
package groovy.bugs
-import groovy.transform.CompileStatic
import org.junit.Test
import static groovy.test.GroovyAssert.assertScript
-@CompileStatic
final class Groovy9115 {
@Test
- void testSetPropertyInIfStmt() {
+ void testSetProperty1() {
assertScript '''
@groovy.transform.CompileStatic
- class Derived {
- def m() {
- if (true) {
- File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
- file.text = 'Groovy9115Bug'
- assert 'Groovy9115Bug' == file.text
- }
-
- return null
+ void test() {
+ File file = File.createTempFile('test', null)
+ try {
+ file.text = 'GROOVY-9115' // via ResourceGroovyMethods#setText
+ assert file.text == 'GROOVY-9115'
+ } finally {
+ file.delete()
}
}
- new Derived().m()
+ test()
'''
}
@Test
- void testSetProperty() {
+ void testSetProperty2() {
assertScript '''
@groovy.transform.CompileStatic
- class Derived {
- def m() {
- File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
- file.text = 'Groovy9115Bug'
- assert 'Groovy9115Bug' == file.text
-
- return null
+ void test() {
+ if (true) {
+ File file = File.createTempFile('test', null)
+ try {
+ file.text = 'GROOVY-9115' // via ResourceGroovyMethods#setText
+ assert file.text == 'GROOVY-9115'
+ } finally {
+ file.delete()
+ }
}
}
- new Derived().m()
+ test()
'''
}
}
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 8a53bb6..142ca9c 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -686,20 +686,23 @@
void testMapPropertyAccess5() {
assertScript '''
def map = [:]
- assert map.entry == null
- assert map.empty == null
- assert map.class == null
- assert map.metaClass == null // TODO
+ assert map.entry == null
+ assert map.empty == null
+ assert map.class == null
+ assert map.metaClass == null // TODO
+ assert map.properties != null
- map.entry = null
- map.empty = null // not read-only property
- map.class = null // not read-only property
- map.metaClass = null // not read-only property
+ map.entry = null
+ map.empty = null // not read-only property
+ map.class = null // not read-only property
+ map.metaClass = null // not read-only property
+ map.properties = null
assert map.containsKey('entry')
assert map.containsKey('empty')
assert map.containsKey('class')
assert !map.containsKey('metaClass')
+ assert map.containsKey('properties')
'''
}
@@ -1621,7 +1624,6 @@
class BooleanSetterOnly {
void setFlag(boolean b) {}
}
-
def b = new BooleanSetterOnly()
b.flag = 'foo'
'''
@@ -1629,7 +1631,6 @@
class StringSetterOnly {
void setFlag(String b) {}
}
-
def b = new StringSetterOnly()
b.flag = false
'''
@@ -1637,7 +1638,6 @@
class ClassSetterOnly {
void setFlag(Class b) {}
}
-
def b = new ClassSetterOnly()
b.flag = 'java.lang.String'
'''
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
index 3b6236c..5081b0f 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
@@ -239,7 +239,7 @@
assert new D().m() == 0
"""
def d = astTrees['D'][1]
- assert d.contains('GETFIELD C.x')
+ assert d.contains('GETFIELD C.x')
}
}
@@ -859,7 +859,7 @@
'''
}
- // GROOVY-5001, GROOVY-5491, GROOVY-11367, GROOVY-11369
+ // GROOVY-5001, GROOVY-5491, GROOVY-11367, GROOVY-11369, GROOVY-11370
void testMapPropertyAccess() {
assertScript '''
Map<String,Number> map = [:]
@@ -880,9 +880,14 @@
def c = map.metaClass
@ASTTest(phase=INSTRUCTION_SELECTION, value={
+ assert node.getNodeMetaData(INFERRED_TYPE) == MAP_TYPE
+ })
+ def d = map.properties
+
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
assert node.getNodeMetaData(INFERRED_TYPE) == Number_TYPE
})
- def d = map.something
+ def e = map.some_thing
'''
}