Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370232 - Casts don't appear to coerce closures
Summary: Casts don't appear to coerce closures
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.3.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 370173 403032 (view as bug list)
Depends on: 376037
Blocks:
  Show dependency tree
 
Reported: 2012-01-31 10:43 EST by William R. Burdick Jr. CLA
Modified: 2013-05-27 06:10 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description William R. Burdick Jr. CLA 2012-01-31 10:43:04 EST
Build Identifier: 

Closures don't get type information from a cast.

This works:

var Function<Integer,Integer> s = [x|x * 2]


but this doesn't:

var s = [x|x * 2] as Function<Integer,Integer>

Reproducible: Always

Steps to Reproduce:
1. try to compile this declaraion:

var s = [x|x * 2] as Function<Integer,Integer>
Comment 1 Sven Efftinge CLA 2012-01-31 11:04:03 EST
*** Bug 370173 has been marked as a duplicate of this bug. ***
Comment 2 Sven Efftinge CLA 2012-01-31 11:05:10 EST
Casts are generally not used in expected type inference. See also : http://groups.google.com/group/xtend-lang/browse_thread/thread/63a2181439fef757
Comment 3 William R. Burdick Jr. CLA 2012-02-01 12:02:20 EST
This becomes more important when closures can coerce to abstract classes, because you may have several abstract classes implementing the same interface.

With your patch to allow casts to work for this, I can now choose an abstract class by casting a literal closure.  I have a closure-compatible abstract class (given my patch), called SimpleSelectionAdapter, that implements SWT's SelectionListener interface and leaves only widgetSelected() abstract and I can use a closure for it, like this:


menuItem.addSelectionListener([e|...] as SimpleSelectionAdapter)


If the cast doesn't work, I need to declare a new variable for this, which seems counter to Xtend's focus on programmer convenience.
Comment 4 Sven Efftinge CLA 2012-04-04 02:25:16 EDT
Something we should look at while reworking the linking / type system
Comment 5 Dennis Huebner CLA 2013-02-14 04:35:44 EST
Is an enhancement.
Comment 6 Sebastian Zarnekow CLA 2013-03-12 09:06:19 EDT
see also bug 403032
Comment 7 Sven Efftinge CLA 2013-03-12 09:07:07 EDT
*** Bug 403032 has been marked as a duplicate of this bug. ***