[jira] [Commented] (GROOVY-8283) Field shadowing not considered in STC
[ https://issues.apache.org/jira/browse/GROOVY-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17581963#comment-17581963 ] ASF GitHub Bot commented on GROOVY-8283: eric-milles opened a new pull request, #1767: URL: https://github.com/apache/groovy/pull/1767 For the dynamic side of 8283, field can be selected in `MetaClassImpl`. If access method is declared by an interface, the interface method is the one indexed so it is considered pervasive in the type hierarchy (cannot be safely hidden). Not sure if this kind of name hiding should be extended to inner classes; hopefully the commit is enough of a first step to determine if this protocol should be changed or left alone. @blackdrag @paulk-asert TODO: - setter method - STC selection of field vs method (verify what `StaticTypeCheckingVisitor` does vs `MetaClassImpl`) - static compiler classgen > Field shadowing not considered in STC > - > > Key: GROOVY-8283 > URL: https://issues.apache.org/jira/browse/GROOVY-8283 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 2.4.12 >Reporter: Daniil Ovchinnikov >Assignee: Eric Milles >Priority: Major > Labels: breaking > > {code} > import groovy.transform.CompileStatic > @CompileStatic class A {} > @CompileStatic class B {} > @CompileStatic class Parent { > protected A ff = new A() > A getFf() { ff } > } > @CompileStatic class Child extends Parent { > protected B ff = new B() > } > @CompileStatic class Usage extends Child { > def test() { > println ff// A@id > println getFf() // A@id > println this.@ff // B@id > } > def test2() { > I.wantsB(ff)// > ScriptBytecodeAdapter.castToType(((Usage)this).getFf(), B.class)) is > generated (wrong) > I.wantsB(getFf()) // [STC] - Cannot find matching method I#wantsB(A) > I.wantsB(this.@ff) // [STC] - Cannot find matching method I#wantsB(A) > (wrong) > } > } > @CompileStatic class I { > static void wantsB(B b) {} > } > new Usage().test() > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (GROOVY-8283) Field shadowing not considered in STC
[ https://issues.apache.org/jira/browse/GROOVY-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17487691#comment-17487691 ] Jochen Theodorou commented on GROOVY-8283: -- Child#ff should be preferred over Parent#ff and Parent#getFf() in "Usage", iff ff is accessed using "this", implicit or not. In Parent this.ff should always access Parent#ff. Thus {code:java} println ff // should give Child@ff because of implicit this println getFf() // should give Parent@ff through Parent#getFf() println this.@ff// should only access the field, thus Child#ff I.wantsB(ff)// should work through Child#ff I.wantsB(getFf()) // should fail, because of Parent#getFf() returns A, not B I.wantsB(this.@ff) // should work through Child#ff{code} And these rules should be (in this case at least) the same with or without static compilation. That is of course not covering what happens if we are not working on "this". > Field shadowing not considered in STC > - > > Key: GROOVY-8283 > URL: https://issues.apache.org/jira/browse/GROOVY-8283 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 2.4.12 >Reporter: Daniil Ovchinnikov >Priority: Major > > {code} > import groovy.transform.CompileStatic > @CompileStatic class A {} > @CompileStatic class B {} > @CompileStatic class Parent { > protected A ff = new A() > A getFf() { ff } > } > @CompileStatic class Child extends Parent { > protected B ff = new B() > } > @CompileStatic class Usage extends Child { > def test() { > println ff// A@id > println getFf() // A@id > println this.@ff // B@id > } > def test2() { > I.wantsB(ff)// > ScriptBytecodeAdapter.castToType(((Usage)this).getFf(), B.class)) is > generated (wrong) > I.wantsB(getFf()) // [STC] - Cannot find matching method I#wantsB(A) > I.wantsB(this.@ff) // [STC] - Cannot find matching method I#wantsB(A) > (wrong) > } > } > @CompileStatic class I { > static void wantsB(B b) {} > } > new Usage().test() > {code} -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Commented] (GROOVY-8283) Field shadowing not considered in STC
[ https://issues.apache.org/jira/browse/GROOVY-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17487511#comment-17487511 ] Eric Milles commented on GROOVY-8283: - Dynamic and static compilation both select the public accessor of A. It is not a simple matter of "protected B ff" shadows "protected A ff". There is some confusion in STC because it searches class by class up the type hierarchy and stops at the field of B. [~paulk] [~blackdrag] Do you think there is anything left to do here? I suppose STC inference could match the runtime, but there are other instances of this happening since property resolution is actually split into two parts ({{StaticTypeCheckingVisitor}} and {{StaticTypesCallSiteWriter}}). GROOVY-6277 is one example. Here is another: https://github.com/groovy/groovy-eclipse/issues/1326 > Field shadowing not considered in STC > - > > Key: GROOVY-8283 > URL: https://issues.apache.org/jira/browse/GROOVY-8283 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 2.4.12 >Reporter: Daniil Ovchinnikov >Priority: Major > > {code} > import groovy.transform.CompileStatic > @CompileStatic class A {} > @CompileStatic class B {} > @CompileStatic class Parent { > protected A ff = new A() > A getFf() { ff } > } > @CompileStatic class Child extends Parent { > protected B ff = new B() > } > @CompileStatic class Usage extends Child { > def test() { > println ff// A@id > println getFf() // A@id > println this.@ff // B@id > } > def test2() { > I.wantsB(ff)// > ScriptBytecodeAdapter.castToType(((Usage)this).getFf(), B.class)) is > generated (wrong) > I.wantsB(getFf()) // [STC] - Cannot find matching method I#wantsB(A) > I.wantsB(this.@ff) // [STC] - Cannot find matching method I#wantsB(A) > (wrong) > } > } > @CompileStatic class I { > static void wantsB(B b) {} > } > new Usage().test() > {code} -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Commented] (GROOVY-8283) Field shadowing not considered in STC
[ https://issues.apache.org/jira/browse/GROOVY-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16962358#comment-16962358 ] Eric Milles commented on GROOVY-8283: - {{StaticTypeCheckingVisitor#existsProperty}} does this resolution. It currently prefers accessors and properties over fields. > Field shadowing not considered in STC > - > > Key: GROOVY-8283 > URL: https://issues.apache.org/jira/browse/GROOVY-8283 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 2.4.12 >Reporter: Daniil Ovchinnikov >Priority: Major > > {code} > import groovy.transform.CompileStatic > @CompileStatic class A {} > @CompileStatic class B {} > @CompileStatic class Parent { > protected A ff = new A() > A getFf() { ff } > } > @CompileStatic class Child extends Parent { > protected B ff = new B() > } > @CompileStatic class Usage extends Child { > def test() { > println ff// A@id > println getFf() // A@id > println this.@ff // B@id > } > def test2() { > I.wantsB(ff)// > ScriptBytecodeAdapter.castToType(((Usage)this).getFf(), B.class)) is > generated (wrong) > I.wantsB(getFf()) // [STC] - Cannot find matching method I#wantsB(A) > I.wantsB(this.@ff) // [STC] - Cannot find matching method I#wantsB(A) > (wrong) > } > } > @CompileStatic class I { > static void wantsB(B b) {} > } > new Usage().test() > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (GROOVY-8283) Field shadowing not considered in STC
[ https://issues.apache.org/jira/browse/GROOVY-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16592753#comment-16592753 ] Daniel Sun commented on GROOVY-8283: Hi [~daniilo] Have you tried the latest version on master? In addition, I wish you could provide test code with `assert` > Field shadowing not considered in STC > - > > Key: GROOVY-8283 > URL: https://issues.apache.org/jira/browse/GROOVY-8283 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 2.4.12 >Reporter: Daniil Ovchinnikov >Priority: Major > > {code} > import groovy.transform.CompileStatic > @CompileStatic class A {} > @CompileStatic class B {} > @CompileStatic class Parent { > protected A ff = new A() > A getFf() { ff } > } > @CompileStatic class Child extends Parent { > protected B ff = new B() > } > @CompileStatic class Usage extends Child { > def test() { > println ff// A@id > println getFf() // A@id > println this.@ff // B@id > } > def test2() { > I.wantsB(ff)// > ScriptBytecodeAdapter.castToType(((Usage)this).getFf(), B.class)) is > generated (wrong) > I.wantsB(getFf()) // [STC] - Cannot find matching method I#wantsB(A) > I.wantsB(this.@ff) // [STC] - Cannot find matching method I#wantsB(A) > (wrong) > } > } > @CompileStatic class I { > static void wantsB(B b) {} > } > new Usage().test() > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (GROOVY-8283) Field shadowing not considered in STC
[ https://issues.apache.org/jira/browse/GROOVY-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16121403#comment-16121403 ] Daniil Ovchinnikov commented on GROOVY-8283: This issue prevents using {{io.vertx.rxjava.core.AbstractVerticle}} in Groovy without workarounds (https://youtrack.jetbrains.com/issue/IDEA-177371) > Field shadowing not considered in STC > - > > Key: GROOVY-8283 > URL: https://issues.apache.org/jira/browse/GROOVY-8283 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker >Affects Versions: 2.4.12 >Reporter: Daniil Ovchinnikov > > {code} > import groovy.transform.CompileStatic > @CompileStatic class A {} > @CompileStatic class B {} > @CompileStatic class Parent { > protected A ff = new A() > A getFf() { ff } > } > @CompileStatic class Child extends Parent { > protected B ff = new B() > } > @CompileStatic class Usage extends Child { > def test() { > println ff// A@id > println getFf() // A@id > println this.@ff // B@id > } > def test2() { > I.wantsB(ff)// > ScriptBytecodeAdapter.castToType(((Usage)this).getFf(), B.class)) is > generated (wrong) > I.wantsB(getFf()) // [STC] - Cannot find matching method I#wantsB(A) > I.wantsB(this.@ff) // [STC] - Cannot find matching method I#wantsB(A) > (wrong) > } > } > @CompileStatic class I { > static void wantsB(B b) {} > } > new Usage().test() > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)