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

Bug 341550

Summary: [xbase] [compiler] generated Java generic type references sometimes wrong
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sven.efftinge
Version: 2.0.0Flags: sven.efftinge: indigo+
Target Milestone: M7   
Hardware: All   
OS: All   
Whiteboard:

Description Knut Wannheden CLA 2011-03-31 17:11:35 EDT
Given the following Xtend function:

	foo() {
		switch emptyList() {
			case null : emptyList()
		}
	}

the compiler produces:

  public List<? extends Object> foo() {
    List<T> switchResult = null; // ERROR HERE
    List<?> _emptyList = CollectionLiterals.emptyList();
    final List<T> emptyList = _emptyList; // ERROR HERE
    boolean matched = false;
    if (!matched) {
      if (org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_equals(emptyList,null)) {
        matched=true;
        List<?> _emptyList_1 = CollectionLiterals.emptyList();
        switchResult = _emptyList_1;
      }
    }
    return switchResult;
  }

The type of variables switchResult and emptyList should of course be List<?> instead of List<T>. To cause seems to be the type references produced by StringBuilderBasedAppendable#appendTypeRef(). AbstractXbaseCompiler#serialize() OTOH produces the correct result.

A workaround is to define the function as follows (note the first parameterized call to emptyList() required due to this bug):

	<T> foo2() {
		switch <T> emptyList() {
			case null : <T> emptyList()
		}
	}

This compiles to:

  public <T> List<?> foo2() {
    List<T> switchResult = null;
    List<T> _emptyList = CollectionLiterals.emptyList();
    final List<T> emptyList = _emptyList;
    boolean matched = false;
    if (!matched) {
      if (org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_equals(emptyList,null)) {
        matched=true;
        List<T> _emptyList_1 = CollectionLiterals.emptyList();
        switchResult = _emptyList_1;
      }
    }
    return switchResult;
  }

which compiles correctly, but the return type should preferably be derived as List<T>. But I suppose this is really a different bug.
Comment 1 Sven Efftinge CLA 2011-04-04 09:32:54 EDT
The type references are now correctly generated using a wildcard.
Pushed to master.
Comment 2 Karsten Thoms CLA 2017-09-19 17:28:13 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 3 Karsten Thoms CLA 2017-09-19 17:39:23 EDT
Closing all bugs that were set to RESOLVED before Neon.0