Scott Murphy Heiberg created GROOVY-12525:
---------------------------------------------

             Summary: STC accepts a call to an isX() or getX() accessor that 
the property does not generate
                 Key: GROOVY-12525
                 URL: https://issues.apache.org/jira/browse/GROOVY-12525
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 6.0.0
            Reporter: Scott Murphy Heiberg


The type checker accepts a call to an accessor method that a property would 
generate, also when the property does not generate it, and the call then fails 
at run time in every mode:

{code:groovy}
@groovy.transform.TypeChecked
class Box {
    boolean flag = true
    boolean getFlag() { flag } // with an explicit getFlag(), no isFlag() is 
generated
}
@groovy.transform.TypeChecked
class C {
    boolean test(Box b) { b.isFlag() }
}
new C().test(new Box()) // MissingMethodException: No signature of method: 
isFlag for class: Box
{code}

Dynamic Groovy throws the same exception. Under {{@CompileStatic}} the call 
compiles to {{Box.isFlag()}} and fails with {{NoSuchMethodError: 'boolean 
Box.isFlag()'}}. The same happens for {{b.getFlag()}} when {{Box}} declares 
{{isFlag()}} instead, and for {{b.isFlag()}} on a {{Boolean flag}} property, 
which only gets {{getFlag()}}. Without an explicit accessor, a {{boolean}} 
property gets both, and the call works. Seen in 4.0.33, 5.0.8, 6.0.0 and master.

Expected: "Cannot find matching method Box#isFlag()".



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to