Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 416516 - Vararg regular methods being wrongly interpreted as extension methods
Summary: Vararg regular methods being wrongly interpreted as extension methods
Status: CLOSED FIXED
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.4.2   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: v2.5
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-04 08:04 EDT by Javier Fernandes CLA
Modified: 2017-10-31 11:26 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Javier Fernandes CLA 2013-09-04 08:04:10 EDT
When trying to call a regular method defined in the same class (or superclass) which receives a varargs of the same class, then xtend includes the "this" (target object) both, as real target of the method, but also as first parameter within the varargs.
So it treats it as an extension method.

It's actually easier to explain in code :) 
Here's a sample code:

class AClass {
   
    def doSomething(AClass... otherInstance) {
        print("blah")   
    }
   
    def doSomeOtherThingWith(AClass other) {
        this.doSomething(other)
    }
   
}

What's important here is that in the "doSomeOtherThingWith" we will like to call ourselves the doSomething() just passing the "other" instance as a single parameter to "doSomething".

The problem arises because xtend thinks that we are trying to it as an extension methods, and generates this:

String _doSomething = this.doSomething(this, other);

I know using varargs is not always a good idea, but in this case the real problem (this is just a simplified version) comes using Apache Wicket's "add(Component...)" method which unfortunately I cannot change.

Also I would think that any non-static method defined in the same class or superclass would be more like a regular method, unless specified somehow as extension method.

I think that I've faced a similar issue in some other case without a vararg, but I cannot reproduce it anymore :(
Comment 1 Sebastian Zarnekow CLA 2013-09-09 13:22:42 EDT
Thanks for the repro. I pushed the fix to review. It'll be available in the next nightly build and the next release respectively.
Comment 2 Eclipse Webmaster CLA 2017-10-31 11:26:44 EDT
Requested via bug 522520.

-M.