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:57:22 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 1adf56c1a -> 8ca1908d6


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

(cherry picked from commit 6ee3977)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 8ca1908d655c819657e31fe7e9711a4873e4c1c8
Parents: 1adf56c
Author: alexey.afanasiev <alexey.afanasiev@jetbrains.com>
Authored: Tue Sep 26 22:43:15 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Wed Sep 27 14:57:16 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/8ca1908d/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 915f988..b30d27d 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3350,6 +3350,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/8ca1908d/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