[
https://issues.apache.org/jira/browse/GROOVY-12821?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149424#comment-18149424
]
ASF GitHub Bot commented on GROOVY-12821:
-----------------------------------------
testlens-app[bot] commented on PR #3332:
URL: https://github.com/apache/groovy/pull/3332#issuecomment-7085936827
## ✅ All tests passed ✅
🏷️ Commit: 0ffe037efb341af7bbf8486fcd3d537112c83b12
▶️ Tests: 261 executed
⚪️ Checks: 24/24 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> SC: ClassCastException when a closure shared variable is assigned instances
> of two different subclasses
> -------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12821
> URL: https://issues.apache.org/jira/browse/GROOVY-12821
> Project: Groovy
> Issue Type: Bug
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> On master (09e84fa), JDK 25.0.4:
> {code:groovy}
> @groovy.transform.CompileStatic
> class Outer {
> static class Box {
> String id = 'box'
> String pm() { 'pm:' + id }
> static String t() { Sub s = new Sub1(); def c = { -> s.pm() }; s =
> new Sub2(); c() }
> }
> static class Sub extends Box { }
> static class Sub1 extends Sub { Sub1() { id = 'sub1' } }
> static class Sub2 extends Sub { Sub2() { id = 'sub2' } }
> }
> assert Outer.Box.t() == 'pm:sub2'
> {code}
> Dynamic Groovy and {{@TypeChecked}} return {{pm:sub2}}. Under
> {{@CompileStatic}} it compiles and throws ClassCastException at run time
> ({{Outer$Sub2}} cannot be cast to {{Outer$Sub1}}): the shared variable is
> cast to the type of its first assignment.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)