You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/05 17:37:00 UTC
[jira] [Commented] (GROOVY-6328) onMethodSelection() doesn't fire
when setter is called with property syntax
[ https://issues.apache.org/jira/browse/GROOVY-6328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17424620#comment-17424620 ]
Eric Milles commented on GROOVY-6328:
-------------------------------------
For "setBrand(...);" there is a {{MethodNode}} created for the property within {{org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor#findMethod}} that then passes through the typical method selection process.
For "brand = ...;", {{StaticTypeCheckingVisitor}} selects the actual {{PropertyNode}}, unless there is an explicit setter declared in the source. {{StaticTypeCheckingVisitor#existsProperty}} is where this happens.
If an explicit setter is declared, {{StaticTypeCheckingVisitor#ensureValidSetter}} triggers a callback for the dummy expression "%.setBrand('BMW')". To also get a callback for the binary expression, a call to {{extension.onMethodSelection(expression, methodTarget);}} could be added below {{setType(...)}}.
> onMethodSelection() doesn't fire when setter is called with property syntax
> ---------------------------------------------------------------------------
>
> Key: GROOVY-6328
> URL: https://issues.apache.org/jira/browse/GROOVY-6328
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 2.2.0-beta-1
> Reporter: Peter Niederwieser
> Priority: Major
>
> {code}
> import groovy.transform.TypeChecked
> @TypeChecked
> class MyCar {
> String brand
> }
> @TypeChecked(extensions = ["MyChecker.grovy"])
> class MyCarMain {
> static void main(String[] args) {
> def main = new MyCarMain()
> main.configureCar {
> brand = "BMW"
> }
> }
> MyCar configureCar(@DelegatesTo(MyCar) Closure closure) {
> def car = new MyCar()
> closure.delegate = car
> closure.resolveStrategy = Closure.DELEGATE_FIRST
> closure.call()
> car
> }
> }
> {code}
> Same when {{MyCar}} declares explicit getter and setter instead of property. Changing to {{setBrand("BMW")}} solves the problem.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)