1818 */
1919package groovy.transform.stc
2020
21- import groovy.test.NotYetImplemented
2221import org.codehaus.groovy.ast.ClassHelper
2322import org.codehaus.groovy.ast.ClassNode
2423import org.codehaus.groovy.ast.MethodNode
@@ -44,7 +43,7 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
4443
4544 // GROOVY-9935
4645 void testIntegerToNumber () {
47- [' def' , ' int' , ' Integer' , ' BigInteger' ]. each { type ->
46+ for (type in [' def' , ' int' , ' Integer' , ' BigInteger' ]) {
4847 assertScript """
4948 Number f() {
5049 $type n = 10
@@ -242,23 +241,29 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
242241 '''
243242 }
244243
245- // GROOVY-10096
246- @NotYetImplemented
244+ // GROOVY-11769
247245 void testInstanceOf10 () {
248- shouldFailWithMessages '''
249- class Foo {
250- void foo() {
251- }
246+ assertScript '''
247+ abstract class Foo {
248+ abstract boolean isBaz()
252249 }
253250 class Bar extends Foo {
254- void bar() {
255- }
251+ final boolean baz = false
256252 }
257- static Bar baz(Foo foo) {
258- (false || foo instanceof Bar) ? foo : new Bar()
253+ class Baz extends Foo {
254+ final boolean baz = true
259255 }
260- ''' ,
261- ' Cannot return value of type Foo for method returning Bar'
256+
257+ void test(Foo foo) {
258+ if (foo instanceof Bar || foo.isBaz()) {
259+ foo.toString()
260+ }
261+ }
262+
263+ test(new Bar())
264+ test(new Baz())
265+ test(new Foo(){ boolean isBaz() { false } })
266+ '''
262267 }
263268
264269 // GROOVY-11007
@@ -699,11 +704,11 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
699704
700705 void testInstanceOfInferenceWithImplicitIt () {
701706 assertScript '''
702- ['a', 'b', 'c'].each {
703- if (it instanceof String) {
704- println it.toUpperCase()
707+ ['a', 'b', 'c'].each {
708+ if (it instanceof String) {
709+ println it.toUpperCase()
710+ }
705711 }
706- }
707712 '''
708713 }
709714
@@ -972,20 +977,19 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
972977 void call (SourceUnit source , GeneratorContext context , ClassNode classNode ) {
973978 method = classNode. methods. find { it. name == ' method' }
974979 }
975-
976980 })
981+
977982 assertScript '''
978983 void method() {
979984 def o
980985 o = 1
981986 o = 'String'
982987 }
983988 '''
984- def inft = method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE )
985- assert inft instanceof WideningCategories.LowestUpperBoundClassNode
986- [Comparable , Serializable ]. each {
987- assert ClassHelper . make(it) in inft. interfaces
988- }
989+ ClassNode type = method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE )
990+ assert type instanceof WideningCategories.LowestUpperBoundClassNode
991+ assert ClassHelper . make(Comparable ) in type. interfaces
992+ assert ClassHelper . make(Serializable ) in type. interfaces
989993
990994 assertScript '''
991995 void method() {
@@ -994,7 +998,8 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
994998 o = 2
995999 }
9961000 '''
997- assert method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE ) == ClassHelper . int_TYPE
1001+ type = method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE )
1002+ assert type == ClassHelper . int_TYPE
9981003
9991004 assertScript '''
10001005 void method() {
@@ -1003,8 +1008,8 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
10031008 o = 2
10041009 }
10051010 '''
1006- inft = method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE )
1007- assert inft == ClassHelper . long_TYPE
1011+ type = method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE )
1012+ assert type == ClassHelper . long_TYPE
10081013
10091014 assertScript '''
10101015 void method() {
@@ -1013,7 +1018,8 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
10131018 o = new LinkedHashSet()
10141019 }
10151020 '''
1016- assert method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE ) == ClassHelper . make(HashSet )
1021+ type = method. code. statements[0 ]. expression. leftExpression. getNodeMetaData(StaticTypesMarker . DECLARATION_INFERRED_TYPE )
1022+ assert type == ClassHelper . make(HashSet )
10171023 }
10181024
10191025 void testChooseMethodWithTypeInference () {
@@ -1575,7 +1581,7 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
15751581 '''
15761582 }
15771583
1578- // GROOVY-
1584+ // GROOVY-6207
15791585 void testGetAnnotationFails () {
15801586 assertScript '''
15811587 import groovy.transform.*
0 commit comments