Bug 436483 - [xbase][linking] Overload resolution can be improved for static methods
Summary: [xbase][linking] Overload resolution can be improved for static methods
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.6.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-03 11:57 EDT by Sebastian Zarnekow CLA
Modified: 2014-06-03 11:57 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 Sebastian Zarnekow CLA 2014-06-03 11:57:18 EDT
import com.google.common.base.Optional
import static java.lang.Enum.*

class C {
  def static void valueOf(Object o, Object context) {}
  def Object m() {
    val idx = valueOf(null, null)
    return idx
  }
}

Due to the static import, #valueOf is overloaded with C.valueOf(Object, Object) and Enum.<T>valueOf(Class<T>, String). The latter is more specific in the sense that the argument types match both overloaded signatures but Class and String are more specific parameter types than Object, Object. Java does not support this kind of overloading and would always bind to the local declaration, independently from the given arguments - even for obvious mismatches like 

  static void valueOf(Object o, Integer context) {}
  Object m() {
    valueOf(RetentionPolicy.class, "");
    return null;
  }

where the local signature does not match at all. Generally speaking, Xtend has an advantage here. However, since the given invocation

valueOf(null, null)

does not give any hints on the value of the type parameter <T> of Enum.valueOf thus it has to be bound to <?> which would not fulfill the constraints of T extends Enum<T>. Therefore, the local valueOf(Object,Object) declaration would be a better choice in this scenario.
Comment 1 Sebastian Zarnekow CLA 2014-06-03 11:57:44 EDT
see org.eclipse.xtend.core.tests.compiler.CompilerBug435133Test.testBug436483_01()