[
https://issues.apache.org/jira/browse/GROOVY-12305?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18109340#comment-18109340
]
ASF GitHub Bot commented on GROOVY-12305:
-----------------------------------------
blackdrag commented on code in PR #2839:
URL: https://github.com/apache/groovy/pull/2839#discussion_r3884966297
##########
src/test/groovy/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy:
##########
@@ -1321,6 +1321,30 @@ class FieldsAndPropertiesSTCTest extends
StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-12305
+ @Test
+ void testMapPropertyAccess19() {
+ assertScript '''
+ def test(Map foo) {
+ foo.a instanceof Map ? foo.a.b : foo.a
Review Comment:
I think the test is ok, but does it works with generics too?
> STC vs static compile: type-coercion in ternary expression is not handled
> properly in static compilation
> --------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12305
> URL: https://issues.apache.org/jira/browse/GROOVY-12305
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0-alpha-1, 5.0.3, 4.0.31
> Reporter: Björn Kautler
> Priority: Major
>
> This compiles and runs fine, printing {{{}c{}}}:
> {code:java}
> @groovy.transform.TypeChecked
> class Foo {
> def foo() {
> Map foo = [a:[b:'c']] as Map
> println(foo.a instanceof Map ? foo.a.b : foo.a)
> }
> }
> new Foo().foo(){code}
> If you swap {{TypeChecked}} for {{{}CompileStatic{}}}, it fails to compile at
> class generation phase, complaining that "Access to java.lang.Object#b is
> forbidden".
--
This message was sent by Atlassian Jira
(v8.20.10#820010)