Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367678

Summary: sub types wrongly assumed to be a super type (affects instanceof, dispatch)
Product: [Modeling] TMF Reporter: Meinte Boersma <meinte.boersma>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sven.efftinge
Version: unspecifiedFlags: sven.efftinge: juno+
Target Milestone: M5   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
example Eclipse project which exhibits the problem none

Description Meinte Boersma CLA 2011-12-31 07:22:57 EST
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
Comment 1 Meinte Boersma CLA 2011-12-31 07:24:10 EST
Created attachment 208890 [details]
example Eclipse project which exhibits the problem
Comment 2 Sven Efftinge CLA 2012-01-03 05:41:55 EST
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.
Comment 3 Sven Efftinge CLA 2012-01-03 05:52:41 EST
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.
Comment 4 Sven Efftinge CLA 2012-01-04 08:15:12 EST
pushed to master
Comment 5 Karsten Thoms CLA 2017-09-19 17:00:38 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 6 Karsten Thoms CLA 2017-09-19 17:12:00 EDT
Closing all bugs that were set to RESOLVED before Neon.0