Bug 502447 - Wrong type inference causes adding type parameter to change generated code behavior
Summary: Wrong type inference causes adding type parameter to change generated code be...
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.9.0   Edit
Hardware: Macintosh Mac OS X
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-28 11:01 EDT by Denes Harmath CLA
Modified: 2016-09-28 11:01 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Denes Harmath CLA 2016-09-28 11:01:32 EDT
@Data
class Foo implements Comparable<Foo> {
	int index

	override compareTo(Foo that) {
		val byIndex = Ordering.natural.onResultOf[index]
		byIndex.compare(this, that)
	}

}

generates:

@Data
@SuppressWarnings("all")
public class Foo implements Comparable<Foo> {
  private final int index;
  
  @Override
  public int compareTo(final Foo that) {
    int _xblockexpression = (int) 0;
    {
      Ordering<Integer> _natural = Ordering.<Integer>natural();
      final Function<Foo, Integer> _function = new Function<Foo, Integer>() {
        @Override
        public Integer apply(final Foo it) {
          return Integer.valueOf(Foo.this.index); // This should be it.index!
        }
      };
      final Ordering<Foo> byIndex = _natural.<Foo>onResultOf(_function);
      _xblockexpression = byIndex.compare(this, that);
    }
    return _xblockexpression;
  }
//  ...
}


If I change the critical line to:

val byIndex = Ordering.natural.onResultOf[it.index]

the compiler gives an error incorrectly:

The method or field index is undefined for the type Foo


If I qualify the onResultOf call:

val byIndex = Ordering.natural.<Foo>onResultOf[index]

then the generated code will look like as expected:

return Integer.valueOf(it.index);


This is probably related to: https://bugs.eclipse.org/bugs/show_bug.cgi?id=422864