You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/05/11 23:16:29 UTC

[groovy] 02/02: minor edits

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 8830e47c3dbd5914e52330d4263c34bcfd05752d
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue May 11 18:16:13 2021 -0500

    minor edits
---
 .../groovy/transform/stc/ReturnsSTCTest.groovy     | 90 ++++++++++++++++------
 .../asm/sc/ReturnsStaticCompileTest.groovy         | 45 +----------
 2 files changed, 66 insertions(+), 69 deletions(-)

diff --git a/src/test/groovy/transform/stc/ReturnsSTCTest.groovy b/src/test/groovy/transform/stc/ReturnsSTCTest.groovy
index f4cd334..ecff4e0 100644
--- a/src/test/groovy/transform/stc/ReturnsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ReturnsSTCTest.groovy
@@ -19,7 +19,7 @@
 package groovy.transform.stc
 
 /**
- * Unit tests for static type checking : implicit and explicit returns.
+ * Unit tests for static type checking : explicit and implicit returns.
  */
 class ReturnsSTCTest extends StaticTypeCheckingTestCase {
 
@@ -102,8 +102,8 @@ class ReturnsSTCTest extends StaticTypeCheckingTestCase {
                 }
             }
         ''',
-            'Cannot return value of type java.lang.String on method returning type int', // first branch
-            'Cannot return value of type java.lang.String on method returning type int' // second branch
+        'Cannot return value of type java.lang.String on method returning type int', // first branch
+        'Cannot return value of type java.lang.String on method returning type int' // second branch
     }
 
     void testImplicitReturnFailureWithSwitch() {
@@ -120,32 +120,22 @@ class ReturnsSTCTest extends StaticTypeCheckingTestCase {
                         3
                  }
              }
-         ''', 'Cannot return value of type java.lang.String on method returning type int'
+         ''',
+         'Cannot return value of type java.lang.String on method returning type int'
     }
 
-
-   void testImplicitReturnFailureWithSwitch2() {
-         assertScript '''
-             int method(int x) {
-                 switch (x) {
+    void testImplicitReturnFailureWithSwitch2() {
+        assertScript '''
+            int method(int x) {
+                switch (x) {
                     case 1:
                         2
                         break
                     case 2:
-                        'String'
+                        'string' // not a return type
                     default:
                         3
-                 }
-             }
-         ''' // should not fail because default case overrides case 2 return type
-     }
-
-    void testImplicitReturnToString() {
-        assertScript '''
-            // automatic toString works
-            String greeting(String name) {
-                def sb = new StringBuilder()
-                sb << "Hi" << name
+                }
             }
         '''
     }
@@ -189,14 +179,25 @@ class ReturnsSTCTest extends StaticTypeCheckingTestCase {
         new Foo().foo(2)
         '''
     }
-    
-    void testInferredReturnTypeWithImplicitConversion() {
+
+    void testImplicitReturnToString1() {
+        assertScript '''
+            // automatic toString works
+            String greeting(String name) {
+                def sb = new StringBuilder()
+                sb << "Hi" << name
+            }
+        '''
+    }
+
+    void testImplicitReturnToString2() {
         shouldFailWithMessages '''
             String methodWithImplicitConversion() {
                 new Date()
             }
             methodWithImplicitConversion().years
-        ''', 'No such property: years for class: java.lang.String'
+        ''',
+        'No such property: years for class: java.lang.String'
     }
 
     // GROOVY-10079
@@ -233,5 +234,44 @@ class ReturnsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
-}
+    void testReturnTypeInferenceWithInheritance() {
+        assertScript '''
+            interface Greeter {
+               public void sayHello()
+            }
+
+            class HelloGreeter implements Greeter {
+               public void sayHello() {
+                   println "Hello world!"
+               }
+            }
 
+            class A {
+               Greeter createGreeter() {
+                   new HelloGreeter()
+               }
+
+               void sayHello() {
+                  // also fails: def greeter = createGreeter()
+                  // successful: def greeter = (Greeter)createGreeter()
+                  Greeter greeter = createGreeter()
+                  greeter.sayHello()
+               }
+            }
+
+            class HelloThereGreeter implements Greeter {
+               public void sayHello() {
+                   println "Hello there!"
+               }
+            }
+
+            class B extends A {
+               Greeter createGreeter() {
+                   new HelloThereGreeter()
+               }
+            }
+
+            new B().sayHello()
+        '''
+    }
+}
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/ReturnsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/ReturnsStaticCompileTest.groovy
index 273acde..e92f59b 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/ReturnsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/ReturnsStaticCompileTest.groovy
@@ -21,50 +21,7 @@ package org.codehaus.groovy.classgen.asm.sc
 import groovy.transform.stc.ReturnsSTCTest
 
 /**
- * Unit tests for static type checking : returns.
+ * Unit tests for static compilation : explicit and implicit returns.
  */
 class ReturnsStaticCompileTest extends ReturnsSTCTest implements StaticCompilationTestSupport {
-
-    void testReturnTypeInferenceWithInheritance() {
-        assertScript '''
-interface Greeter {
-   public void sayHello()
-}
-
-class HelloGreeter implements Greeter {
-   public void sayHello() {
-       println "Hello world!"
-   }
-}
-
-class A {
-   Greeter createGreeter() {
-       new HelloGreeter()
-   }
-
-   void sayHello() {
-      // also fails: def greeter = createGreeter()
-      // successful: def greeter = (Greeter)createGreeter()
-      Greeter greeter = createGreeter()
-      greeter.sayHello()
-   }
-}
-
-class HelloThereGreeter implements Greeter {
-   public void sayHello() {
-       println "Hello there!"
-   }
 }
-
-class B extends A {
-   Greeter createGreeter() {
-       new HelloThereGreeter()
-   }
-}
-
-
-new B().sayHello()'''
-    }
-
-}
-