Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.0
-
None
Description
Consider the following:
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()
"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 not in b" work identically to "not(a in b)" so one cannot implement incongruent "in" and "!in" handling. Otherwise, expected behavior could be restored by disabling GROOVY-10383 optimization when declaring class of isCase and isNotCase differ.
Attachments
Issue Links
- is related to
-
GROOVY-10383 SC: !in compiled to ScriptBytecodeAdapter#isNotCase
- Closed
-
GROOVY-10909 bytecode for in, !in, !() and ?:
- Closed