groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: GROOVY-8330: Wrong 'Inconvertible types' error on casting interface (closes #607)
Date Wed, 27 Sep 2017 06:43:53 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 15607b1ba -> 6ee3977fc


GROOVY-8330: Wrong 'Inconvertible types' error on casting interface
(closes #607)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6ee3977f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6ee3977f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6ee3977f

Branch: refs/heads/master
Commit: 6ee3977fc88a68e0b5b04b8f775e014296a118c0
Parents: 15607b1
Author: alexey.afanasiev <Alexey.Afanasiev@jetbrains.com>
Authored: Tue Sep 26 17:43:15 2017 +0300
Committer: sunlan <sunlan@apache.org>
Committed: Wed Sep 27 14:43:06 2017 +0800

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          |  2 ++
 .../transform/stc/STCAssignmentTest.groovy      | 26 ++++++++++++++++++++
 2 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6ee3977f/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index cbb2798..4c55eea 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3369,6 +3369,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             return false;
         } else if ((expressionType.getModifiers()& Opcodes.ACC_FINAL)==0 && targetType.isInterface())
{
             return true;
+        } else if ((targetType.getModifiers()& Opcodes.ACC_FINAL)==0 && expressionType.isInterface())
{
+            return true;
         } else if (!isAssignableTo(targetType, expressionType) && !implementsInterfaceOrIsSubclassOf(expressionType,
targetType)) {
             return false;
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/6ee3977f/src/test/groovy/transform/stc/STCAssignmentTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/STCAssignmentTest.groovy b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
index 3c00185..acb1c75 100644
--- a/src/test/groovy/transform/stc/STCAssignmentTest.groovy
+++ b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
@@ -872,5 +872,31 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
         }            
         '''
     }
+
+    void testNarrowingConversion() {
+        assertScript '''
+        interface A1{}
+        interface A2 extends A1{}
+        
+        class C1 implements A1{}
+        
+        def m(A2 a2) {
+            C1 c1 = (C1) a2
+        }
+        '''
+    }
+
+    void testFinalNarrowingConversion() {
+        shouldFailWithMessages '''
+        interface A1{}
+        interface A2 extends A1{}
+        
+        final class C1 implements A1{}
+        
+        def m(A2 a2) {
+            C1 c1 = (C1) a2
+        }
+        ''', "Inconvertible types: cannot cast A2 to C1"
+    }
 }
 


Mime
View raw message