Community
Participate
Working Groups
Build Identifier: 20110916-0149 In some circumstances (which I haven't been able to pinpoint precisely) Xtend2 apparently that a sub type is actually a super type. This leads to warnings "<super type> is already of type <sub type>". It also seems to lead to incorrect generation of Java methods handling polymorphic dispatch. As an example, see the attached Eclipse project (Xtext2.2.1): - Generator.xtend shows warnings on 156 and 255 but Classifier is a super type of Datatype so "Classifier instanceof Datatype" is not a tautology; - Generator.java has a method generateFaulty and the statements from line 785 onwards suggest that only Class is recognized as a proper sub type of MetaType (compare the generateInternal method for the intended semantics). Reproducible: Always
Created attachment 208890 [details] example Eclipse project which exhibits the problem
The reason is, that both Datatype and Classifier are functional types. That is they have only one method ()=>String. The dispatcher should really use the Java conformance computer without the Xbase-specific conversion logic. But on the Xbase-level we should try to improve on some surprising situations. For instance, currently the following is valid: val Datatype d = classifier In fact the two types really don't have to be in the same hierarchy and even the methods don't need to have the same name to make this work, because they are assignable because of their functional nature. One way to improve the situation is to require at least one of the two participating types being a real function type. So you would have to cast to make the a conversion from Classifier to Datatype : val Datatype d = classifier as ()=>String Java 8 doesn't do this, so I'm curious how they want to handle these situations.
It looks like in Java 8 only closures and method references can be converted to functional interfaces. So it seems to be appropriate to require at least one functional type in such conversions.
pushed to master
Closing all bugs that were set to RESOLVED before Neon.0