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

Bug 364212

Summary: [Xtend] Type variable causes Xtend to silently generate broken Java
Product: [Tools] Xtend Reporter: McKinley <mckinley1411>
Component: CoreAssignee: Project Inbox <xtend-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: dennis.huebner, sebastian.zarnekow, sven.efftinge
Version: 2.2.0Flags: sven.efftinge: juno+
Target Milestone: M6   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Bug Depends on: 376037    
Bug Blocks:    

Description McKinley CLA 2011-11-19 04:32:28 EST
Build Identifier: 2.2.0.v201111181146

The follow Java and Xtend code causes Xtend to silently generate broken Java. If more type information is needed in Xtend, perhaps the IDE should highlight that error in the Xtend file. The following example was seen in the wild when I recently tried the HtmlUnit library with Xtend.

public interface InterfaceA { }

public class ClassB implements InterfaceA { }

public class ClassC extends ClassB {
    public static <T extends InterfaceA> T newClassBAsInterfaceA() {
        return (T) new ClassC();
    }
}

class XtendClass1 {
    def test() {
        val x = ClassC::newClassBAsInterfaceA
    }
}

This causes Xtend to produce the following broken generated Java code:

@SuppressWarnings("all")
public class XtendClass1 {
  public void test() {
    ? _newClassBAsInterfaceA = ClassC.newClassBAsInterfaceA();
    final ? x = _newClassBAsInterfaceA;
  }
}

Reproducible: Always

Steps to Reproduce:
See above.
Comment 1 Sven Efftinge CLA 2012-01-31 05:42:10 EST
We need to use the type's upper bound in the compiler.
Comment 2 Dennis Huebner CLA 2013-02-14 03:29:44 EST
Given Xtend code produces a valid Java. Seems to be fixed.
Comment 3 Eclipse Webmaster CLA 2017-10-31 10:48:05 EDT
Requested via bug 522520.

-M.
Comment 4 Eclipse Webmaster CLA 2017-10-31 10:59:08 EDT
Requested via bug 522520.

-M.