[jira] [Comment Edited] (GROOVY-11370) STC: extension method cannot provide map property (read mode)

2024-05-23 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-11370?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17844979#comment-17844979
 ] 

Eric Milles edited comment on GROOVY-11370 at 5/23/24 9:15 PM:
---

https://github.com/apache/groovy/commit/9d41af9df4c688ca2c91fa9283ad3462e0abc928
https://github.com/apache/groovy/commit/6e2b9471bc2092c4746677f22bc87eda70cbb253


was (Author: emilles):
https://github.com/apache/groovy/commit/9d41af9df4c688ca2c91fa9283ad3462e0abc928

> STC: extension method cannot provide map property (read mode)
> -
>
> Key: GROOVY-11370
> URL: https://issues.apache.org/jira/browse/GROOVY-11370
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
> Fix For: 3.0.22, 4.0.22
>
>
> Consider the following:
> {code:groovy}
> @TypeChecked
> void test() {
>   def map = [:]
>   print map.metaClass
> }
> test()
> {code}
> The script prints "null" (before Groovy 5) indicating that "getMetaClass()" 
> extension method is not used.  However, node metadata indicates that the 
> extension method is used.  For example, adding "Number n = map.metaClass" 
> says: "Cannot assign value of type groovy.lang.MetaClass to variable of type 
> java.lang.Number"
> GROOVY-5001, GROOVY-5491, GROOVY-5568, GROOVY-9115, GROOVY-9123



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11384) STC: map property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11384:
-
Fix Version/s: 4.0.22

> STC: map property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
> Fix For: 3.0.22, 4.0.22
>
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run as-is, the script prints "entry entry entry entry".  With STC or SC 
> enabled, Groovy 3 or 4 prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11384) STC: map property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11384:
-
Description: 
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run as-is, the script prints "entry entry entry entry".  With STC or SC 
enabled, Groovy 3 or 4 prints "entry true true true".

  was:
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run as-is, prints "entry entry entry entry".  With STC or SC enabled, 
Groovy 3 or 4 prints "entry true true true".


> STC: map property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
> Fix For: 3.0.22
>
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run as-is, the script prints "entry entry entry entry".  With STC or SC 
> enabled, Groovy 3 or 4 prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Resolved] (GROOVY-11384) STC: map property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles resolved GROOVY-11384.
--
Fix Version/s: 3.0.22
   Resolution: Fixed

https://github.com/apache/groovy/commit/afc9a74f4f7523ad7fcde5e00dae9c5905a33c33

> STC: map property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
> Fix For: 3.0.22
>
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run as-is, prints "entry entry entry entry".  With STC or SC enabled, 
> Groovy 3 or 4 prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11384) STC: map property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11384:
-
Description: 
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run as-is, prints "entry entry entry entry".  With STC or SC enabled, 
Groovy 3 or 4 prints "entry true true true".

  was:
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run as-is, prints "entry entry entry entry".  With STC or SC enabled, 
prints "entry true true true".


> STC: map property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run as-is, prints "entry entry entry entry".  With STC or SC enabled, 
> Groovy 3 or 4 prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11384) STC: map property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11384:
-
Description: 
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run as-is, prints "entry entry entry entry".  With STC or SC enabled, 
prints "entry true true true".

  was:
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run by Groovy 3 or 4, prints "entry entry entry entry".  With STC or SC 
enabled, prints "entry true true true".


> STC: map property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run as-is, prints "entry entry entry entry".  With STC or SC enabled, 
> prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11384) STC: map property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11384:
-
Summary: STC: map property access within closure  (was: STC: property 
access within closure)

> STC: map property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run by Groovy 3 or 4, prints "entry entry entry entry".  With STC or SC 
> enabled, prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11384) STC: property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11384:
-
Affects Version/s: 4.0.21

> STC: property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21, 4.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run by Groovy 3 or 4, prints "entry entry entry entry".  With STC or SC 
> enabled, prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11384) STC: property access within closure

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11384?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11384:
-
Description: 
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run by Groovy 3 or 4, prints "entry entry entry entry".  With STC or SC 
enabled, prints "entry true true true".

  was:
Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run by Groovy 3, prints "entry entry entry entry".  With STC or SC 
enabled, prints "entry true true true".


> STC: property access within closure
> ---
>
> Key: GROOVY-11384
> URL: https://issues.apache.org/jira/browse/GROOVY-11384
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 3.0.21
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
>
> Consider the following:
> {code:groovy}
> void test(Map map) {
>   println map.empty
>   println map.with{ empty }
>   println map.with{ delegate.empty }
>   println map.with{ {->owner.empty}() }
> }
> test( [:].withDefault{ 'entry' } )
> {code}
> When run by Groovy 3 or 4, prints "entry entry entry entry".  With STC or SC 
> enabled, prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Created] (GROOVY-11384) STC: property access within closure

2024-05-23 Thread Eric Milles (Jira)
Eric Milles created GROOVY-11384:


 Summary: STC: property access within closure
 Key: GROOVY-11384
 URL: https://issues.apache.org/jira/browse/GROOVY-11384
 Project: Groovy
  Issue Type: Bug
  Components: Static Type Checker
Affects Versions: 3.0.21
Reporter: Eric Milles
Assignee: Eric Milles


Consider the following:
{code:groovy}
void test(Map map) {
  println map.empty
  println map.with{ empty }
  println map.with{ delegate.empty }
  println map.with{ {->owner.empty}() }
}

test( [:].withDefault{ 'entry' } )
{code}

When run by Groovy 3, prints "entry entry entry entry".  With STC or SC 
enabled, prints "entry true true true".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (GROOVY-11367) property semantics of map-based types

2024-05-23 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-11367?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-11367:
-
Description: 
The rules for property read and write for map-based types still have several 
inconsistencies:
{code:groovy}
class M extends HashMap {
  public pub
  protected pro
  @PackageScope pack
  private priv
  def prop
  def getAny() {}
  void setAny(value) {}
}
{code}
 # Read and write do not share a consistent resolution order – noted in 8555. 
Should access method selection take visibility into account? I think sender 
information is not always available to {{MetaClassImpl}} so the "inside class" 
behavior is required.
{code:groovy}
void test1(M map) {
  map.pub  // field (fixed in 5001)
  map.pro  // entry
  map.pack // entry
  map.priv // entry
  map.prop // property (fixed in 5001)
  map.any  // getter (all visibilities -- fixed in 5001) or entry for subclass 
of M (private or package-private other-package subclass -- fixed in 11357)
  map.empty // entry ("class" and "metaClass" as well)

  map.pub  = null // field
  map.pro  = null // field
  map.pack = null // entry
  map.priv = null // entry
  map.prop = null // property
  map.any  = null // setter (all visibilities) or entry for subclass of M 
(private or package-private other-package subclass -- fixed in 11357)
  map.empty = null // entry
  map.class = null // entry
  map.metaClass = null // setter via 
ScriptBytecodeAdapter#setGroovyObjectProperty
}
{code}
 # "this" and "super" have different behavior.
{code:groovy}
  // add this to the body of M
  void test2(M that) {
this.pub  // field
this.pro  // field
this.pack // field
this.priv // field
this.prop // property
this.prop = null // property
this.any  // getter (all visibilities -- fixed in 5001)
this.any = null // setter (all visibilities) or entry for subclass of M 
(private or package-private other-package subclass -- fixed in 11357)
this.class // entry
this.empty // entry
this.metaClass // field (added by compiler)
that.* // see test1
that = this
that.* // see test1
  }
{code}
 # Dynamic and static compilation have different behavior.
{code:groovy}
@groovy.transform.CompileStatic
void test3(M map) {
  map.pub  // field (changed in 5001/5491)
  map.pro  // field (changed in 5001/5491: in package or subclass) or entry
  map.pack // field (changed in 5001/5491: in package) or entry
  map.priv // entry
  map.prop // property (changed in 5001/5491)
  map.any  // getter (accessible -- changed in 5001/5491) or entry 
(inaccessible)
  map.empty // isser (changed in 5001/5491)
  map.class // getter (changed in 5001/5491)
  map.metaClass // getter (changed in 5001/5491)

  map.pub  = null // entry (changed in 6954)
  map.pro  = null // entry (changed in 6954)
  map.pack = null // entry
  map.priv = null // entry
  map.prop = null // property
  map.any  = null // setter (accessible) or error (inaccessible) -- TODO
  map.empty = null // error "Cannot set read-only property: empty" (and 
"class") -- GROOVY-11369
  map.metaClass = null // field or setter (need to determine which)
}
{code}
 # Closures intercept some properties.
{code:groovy}
void test4(M map) {
  map.with {
pub // field
pro // entry
pack // entry
priv // entry
prop // property
directive // closure property
metaClass // closure property (and so on for "owner", "delegate", 
"thisObject", ...)
  }
}
{code}
 # The rules change a bit for fields declared by super class.
{code:groovy}
class MM extends M {
  void test5() {
this.pub   // field (fixed in 5001)
this.pro   // entry
this.pack  // entry
this.priv  // entry
this.prop  // property (fixed in 5001)
this.any   // getter (fixed in 5001) (public, protected, package-private if 
same-package) or entry (private, package-private if other-package)
this.class // entry
this.empty // entry
this.metaClass // entry

this.pub  = null // field
this.pro  = null // field
this.pack = null // entry
this.priv = null // entry
this.prop = null // property
this.any  = null // setter (public, protected, package-private if 
same-package) or entry (private, package-private if other-package -- fixed in 
11357)
this.empty = null // entry
this.class = null // entry
this.metaClass = null // setter via 
ScriptBytecodeAdapter#setGroovyObjectProperty
  }
}
{code}
# Calling a name bypasses map lookup.
{code:groovy}
void test6(M map) {
  map.pack() // field read and call
  map.priv() // field read and call
}
{code}

GROOVY-662, GROOVY-5001, GROOVY-5491, GROOVY-5517, GROOVY-5985, GROOVY-6144, 
GROOVY-6277, GROOVY-6954, GROOVY-8065, GROOVY-8074, GROOVY-8555, GROOVY-9127, 
GROOVY-11319, GROOVY-11223, GROOVY-11368, GROOVY-11369, GROOVY-11370, 
GROOVY-11376 GROOVY-11384

  was:
The rules for property read and write for map-based types still have several 
in