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

Eric Milles updated GROOVY-10915:
---------------------------------
    Description: 
Consider the following:
{code:groovy}
class C {
  boolean isCase(value) {
    System.out.println("C isCase"); true
  }
}
@groovy.transform.CompileStatic // comment out and C#isCase is called for all 3
void test() {
  assert 0 in new C()
  assert !!(0 in new C())
  assert !(0 !in new C())
}
test()
{code}

"x in c" and "!(x in c)" will use C's {{isCase}} method.  However "x !in c" 
will use {{DGM.isNotCase(c,x)}} which static dispatches to {{DGM.isCase}}.  The 
isNotCase extension methods added in Groovy 4 should probably use invokeMethod 
to dynamic dispatch to make use of the isCase implemented by C.

IMO it would be much simpler to ditch "isNotCase" and have "a \!in b" work 
identically to "!(a in b)" so one cannot implement incongruent "in" and "!in" 
handling.

  was:
Consider the following:
{code:groovy}
class C {
  boolean isCase(value) {
    // ...
  }
}
{code}

"x in c" and "!(x in c)" will use C's {{isCase}} method.  However "x !in c" 
will use {{DGM.isNotCase(c,x)}} which static dispatches to {{DGM.isCase}}.  The 
isNotCase extension methods added in Groovy 4 should probably use invokeMethod 
to dynamic dispatch to make use of the isCase implemented by C.

IMO it would be much simpler to ditch "isNotCase" and have "a \!in b" work 
identically to "!(a in b)" so one cannot implement incongruent "in" and "!in" 
handling.


> SC: class that provides isCase but not isNotCase
> ------------------------------------------------
>
>                 Key: GROOVY-10915
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10915
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk, Static compilation
>    Affects Versions: 4.0.0
>            Reporter: Eric Milles
>            Priority: Major
>
> Consider the following:
> {code:groovy}
> class C {
>   boolean isCase(value) {
>     System.out.println("C isCase"); true
>   }
> }
> @groovy.transform.CompileStatic // comment out and C#isCase is called for all 
> 3
> void test() {
>   assert 0 in new C()
>   assert !!(0 in new C())
>   assert !(0 !in new C())
> }
> test()
> {code}
> "x in c" and "!(x in c)" will use C's {{isCase}} method.  However "x !in c" 
> will use {{DGM.isNotCase(c,x)}} which static dispatches to {{DGM.isCase}}.  
> The isNotCase extension methods added in Groovy 4 should probably use 
> invokeMethod to dynamic dispatch to make use of the isCase implemented by C.
> IMO it would be much simpler to ditch "isNotCase" and have "a \!in b" work 
> identically to "!(a in b)" so one cannot implement incongruent "in" and "!in" 
> handling.



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

Reply via email to