Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362240 - [xtend] illegal java generated for generics example
Summary: [xtend] illegal java generated for generics example
Status: CLOSED FIXED
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.2.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: M6   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 376037
Blocks:
  Show dependency tree
 
Reported: 2011-10-27 16:24 EDT by Knut Wannheden CLA
Modified: 2017-10-31 11:19 EDT (History)
3 users (show)

See Also:
sven.efftinge: kepler+


Attachments
StackOverflowError (127.11 KB, text/plain)
2013-02-13 08:01 EST, Dennis Huebner CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Knut Wannheden CLA 2011-10-27 16:24:21 EDT
The following Xtend class:

class Other {
	def <T extends (Object)=>T> T bar(T t) {
		bar(t).apply(bar(t))
	}
}

compiles to the following illegal Java:

import org.eclipse.xtext.xbase.lib.Functions.Function1;

@SuppressWarnings("all")
public class Other {
  public <T extends Function1<? super Object,? extends T>> T bar(final T t) {
    T _bar = this.bar(t);
    T _bar_1 = this.<Object>bar(t); // <- THIS DOES NOT COMPILE
    T _apply = _bar.apply(_bar_1);
    return _apply;
  }
}

Basically the "<Object>" is superfluous and wrong.

Workaround: Change the Xtend code to:

class Other {
	def <T extends (Object)=>T> T bar(T t) {
		bar(t).apply(<T>bar(t))
	}
}
Comment 1 Knut Wannheden CLA 2011-10-27 16:28:08 EDT
A different example with similar problems:

class Other {
	def <T> bar(T t) {
		<Integer>bar(t)
	}
}

does not have any error markers and is compiled to the illegal code:

@SuppressWarnings("all")
public class Other {
  public <T extends Object> Object bar(final T t) {
    Object _bar = this.<Integer>bar(t);
    return _bar;
  }
}
Comment 2 Sebastian Zarnekow CLA 2011-10-28 02:26:35 EDT
(In reply to comment #1)
> A different example with similar problems:
> 
> class Other {
>     def <T> bar(T t) {
>         <Integer>bar(t)
>     }
> }
> 
> does not have any error markers 

Seems to be related to bug 341771
Comment 3 Dennis Huebner CLA 2013-02-13 08:01:24 EST
Created attachment 227011 [details]
StackOverflowError
Comment 4 Dennis Huebner CLA 2013-02-13 08:02:07 EST
class Other {
	def <T extends (Object)=>T> T bar(T t) {
		bar(t).apply(bar(t))
	}
}

Produces java.lang.StackOverflowError see attachment
Comment 5 Dennis Huebner CLA 2013-02-13 08:03:15 EST
class Other {
	def <T extends (Object)=>T> T bar(T t) {
		bar(t).apply(<T>bar(t))
	}
}

Still wont work
Comment 6 Dennis Huebner CLA 2013-02-13 08:14:16 EST
(In reply to comment #5)
> class Other {
> 	def <T extends (Object)=>T> T bar(T t) {
> 		bar(t).apply(<T>bar(t))
> 	}
> }
> 
> Still wont work

Tests add (Ignore):
org.eclipse.xtend.core.tests.compiler.CompilerTest.testGenericsBug362240() 
org.eclipse.xtend.core.tests.compiler.CompilerTest.testGenericsBug362240_1()
Comment 7 Dennis Huebner CLA 2013-02-13 08:23:31 EST
Changing to critical, because eclipse would not start any more, if the last workbench state has an open Xtend editor that contains following code:

def <T extends (Object)=>T> T bar(T t) {
	bar(t).apply(bar(t))
}
Comment 8 Sebastian Zarnekow CLA 2013-02-13 14:09:48 EST
Tests seem to work like a charm with latest. Please reopen if I missed something.
Comment 9 Dennis Huebner CLA 2013-02-13 17:23:21 EST
(In reply to comment #8)
> Tests seem to work like a charm with latest. Please reopen if I missed
> something.
Was it fixed in the meantime?
I've tested it with:
Xtend SDK	2.4.0.v201302121845	org.eclipse.xtend.sdk.feature.group
Comment 10 Eclipse Webmaster CLA 2017-10-31 11:07:49 EDT
Requested via bug 522520.

-M.
Comment 11 Eclipse Webmaster CLA 2017-10-31 11:19:18 EDT
Requested via bug 522520.

-M.