Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341188 - [Xbase / Common Types] Allow multiple types type reference
Summary: [Xbase / Common Types] Allow multiple types type reference
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: M7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-29 02:26 EDT by Sven Efftinge CLA
Modified: 2017-09-19 17:27 EDT (History)
2 users (show)

See Also:
sven.efftinge: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Efftinge CLA 2011-03-29 02:26:01 EDT
In Xbase there are a couple of situations when it would be helpful/necessary to have a TypeReference representing multiple types.

One is in case of branched expressions where multiple common super types are possible, it would be good to pass that information until it is decided which one to use.

Example: 

val x = if (predicate)
     'foo'
  else
     new StringBuilder('foo')

x.compareTo('bar')

(i.e. String and StringBuilder both implement Comparable and CharSequence)

Also in for expression we want to allow arrays or iterables. In order to use TypeProvider's expectedType we need to be able to return a type reference representing both.

There are a couple of existing type inference bugs depending on this.
Comment 1 Sebastian Zarnekow CLA 2011-03-29 11:56:56 EDT
Maybe we should have something like an explicit AnyTypeReference as well instead of using void / java.lang.Void to express the return type of a method

foo() return null

The AnyTypeReference could be serialized to java.lang.Object if no further constraints are present while

dispatch foo(A a) return null
dispatch foo(B b) return ''

could yield java.lang.String for foo(AorB instance) since there the common super type for the AnyTypeReference and type X should be type X.
Comment 2 Sven Efftinge CLA 2011-03-29 16:09:06 EDT
So far we use Void in the signature of dispatch methods to catch null references.
I think effectively java.lang.Void is our AnyRef. Does overloading java.lang.Void cause any problems?
Comment 3 Sebastian Zarnekow CLA 2011-03-30 01:52:39 EDT
(In reply to comment #2)
> So far we use Void in the signature of dispatch methods to catch null
> references.
> I think effectively java.lang.Void is our AnyRef. Does overloading
> java.lang.Void cause any problems?

I've got the impression that the type inference code is harder to read, write and maintain due to the overloaded semantics of java.lang.Void.

There is e.g. the compiler who should usually create java.lang.Object as infered return type when somebody returns null, except when the super method already defined java.lang.Void explicitly (like in MySwitch extends EPackageSwitch<Void>) so we somehow have to maintain additional information with any TypeReference to java.lang.Void whether its intentional or the AnyType. Well, at least that was my impression when I thought about the semantics that we introduced.
Comment 4 Sven Efftinge CLA 2011-03-30 09:18:18 EDT
I've filed a bugzilla for the AnyType issue : #341352
Comment 5 Sven Efftinge CLA 2011-03-30 09:18:59 EDT
(In reply to comment #4)
> I've filed a bugzilla for the AnyType issue : Bug 341352
Comment 6 Sebastian Zarnekow CLA 2011-04-03 13:08:50 EDT
Pushed to master.
Comment 7 Karsten Thoms CLA 2017-09-19 17:16:37 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:27:57 EDT
Closing all bugs that were set to RESOLVED before Neon.0