[GRADLE-2694] Wrong setter used by DSL Created: 26/Feb/13  Updated: 16/Jan/17  Resolved: 16/Jan/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.3, 1.4
Fix Version/s: None

Type: Bug
Reporter: Xavier Ducrohet Assignee: Unassigned
Resolution: Fixed Votes: 0


 Description   

My custom plugin extension has the following methods:
foo(int)
foo(String)
setFoo(int)
setFoo(String).

Depending on the syntax used and the type of the parameter I get the following method called:

foo "14" -> foo(String)
foo 14 -> foo(int)
foo = "14" -> setFoo(String)
foo = 14 -> setFoo(String)

As you can see in the #4 case, the wrong setter is called.



 Comments   
Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 16/Jan/17 ]

The following code calls the correct methods with Gradle 3.3. I am going to close the issue.

def myExt = extensions.create('myExt', MyExtension)

task callExtMethods {
    doLast {
        myExt.foo "14"
        myExt.foo 14
        myExt.foo = "14"
        myExt.foo = 14
    }
}

class MyExtension {
    def foo(int a) {
        println 'foo(int)'
    }
    def foo(String a) {
        println 'foo(String)'
    }
    def setFoo(int a) {
        println 'setFoo(int)'
    }
    def setFoo(String a) {
        println 'setFoo(String)'
    }
}

The output:

$ gradle callExtMethods
:callExtMethods
foo(String)
foo(int)
setFoo(String)
setFoo(int)

BUILD SUCCESSFUL
Generated at Wed Jun 30 12:28:56 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.