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 c7cf9575e3f7d2f1ce93b615233a85d38c1e5ab5 Author: Eric Milles <[email protected]> AuthorDate: Fri Oct 3 18:10:08 2025 -0500 GROOVY-11769: add test case --- .../groovy/groovy/transform/stc/CoercionSTCTest.groovy | 15 +++++++++++++++ .../classgen/asm/sc/CoercionStaticCompileTests.groovy | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/test/groovy/groovy/transform/stc/CoercionSTCTest.groovy b/src/test/groovy/groovy/transform/stc/CoercionSTCTest.groovy index b3cd48094f..79dc18cb9b 100644 --- a/src/test/groovy/groovy/transform/stc/CoercionSTCTest.groovy +++ b/src/test/groovy/groovy/transform/stc/CoercionSTCTest.groovy @@ -211,6 +211,21 @@ class CoercionSTCTest extends StaticTypeCheckingTestCase { ''' } + void testCastObjectToInterface() { + assertScript ''' + List<Object> m(object) { + if (object == null) return new ArrayList<>() + if (object instanceof Collection) return new ArrayList<Object>((Collection) object) + return [object] + } + def item = 0 + def list = [1,2] + assert m(null).size() == 0 + assert m(item).size() == 1 + assert m(list).size() == 2 + ''' + } + void testCastInterfaceToSubclass() { assertScript ''' interface A { diff --git a/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CoercionStaticCompileTests.groovy b/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CoercionStaticCompileTests.groovy index 7506ceb415..d87870cb10 100644 --- a/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CoercionStaticCompileTests.groovy +++ b/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CoercionStaticCompileTests.groovy @@ -24,4 +24,12 @@ import groovy.transform.stc.CoercionSTCTest * Unit tests for static compilation : coercions. */ final class CoercionStaticCompileTests extends CoercionSTCTest implements StaticCompilationTestSupport { + + @Override // GROOVY-11769 + void testCastObjectToInterface() { + super.testCastObjectToInterface() + String bytecode = astTrees.values()[0][1] + bytecode = bytecode.substring(bytecode.indexOf('m(Ljava/lang/Object;)')) + assert bytecode.count('CHECKCAST') == 1 // guarded typecast isn't groovy + } }
