Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368572 - [Xbase] Make type inference control flow aware
Summary: [Xbase] Make type inference control flow aware
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.2.1   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: M6   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-13 12:30 EST by consiliens @gmail.com CLA
Modified: 2017-10-31 11:25 EDT (History)
2 users (show)

See Also:
sebastian.zarnekow: kepler+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description consiliens @gmail.com CLA 2012-01-13 12:30:49 EST
The following code should compile, however it generates invalid Java.

https://gist.github.com/1603753
Comment 1 Sven Efftinge CLA 2012-01-17 03:03:58 EST
You need to provide type information during construction
E.g. 

val builder = ImmutableBiMap::<Integer, String>builder()

or ImmutableBiMapval<Integer, String> builder = ImmutableBiMap::builder()

If you don't do that "? extends Object" is inferred, which isn't compatible to your method definition.

I turn this into a feature enhancement about improving type inference along the control flow.
Comment 2 consiliens @gmail.com CLA 2012-01-17 12:40:53 EST
> val builder = ImmutableBiMap::<Integer, String>builder()
This works.

> ImmutableBiMapval<Integer, String> builder = ImmutableBiMap::builder()
This doesn't work, even after removing val.  What's the proper syntax for specifying type parameters on the left hand side?
Comment 3 Sven Efftinge CLA 2012-01-17 14:02:24 EST
Sorry, it's :

val ImmutableBiMapval<Integer, String> builder = ImmutableBiMap::builder()
Comment 4 consiliens @gmail.com CLA 2012-01-17 14:26:45 EST
(In reply to comment #3)
> Sorry, it's :
> 
> val ImmutableBiMapval<Integer, String> builder = ImmutableBiMap::builder()

Still doesn't work.

// Incompatible types. Expected com.google.common.collect.ImmutableBiMap<java.lang.Integer,java.lang.String> 
// but was com.google.common.collect.ImmutableBiMap.Builder<K,V>	
val ImmutableBiMap<Integer, String> builder = ImmutableBiMap::builder()

I also tried:
import com.google.common.collect.ImmutableBiMap$Builder
// type cannot be derived
val ImmutableBiMap::Builder<Integer, String> builder = ImmutableBiMap::builder()
Comment 5 Sebastian Zarnekow CLA 2013-04-19 05:11:44 EDT
Fixed in 2.4
Comment 6 Eclipse Webmaster CLA 2017-10-31 11:25:37 EDT
Requested via bug 522520.

-M.