Community
Participate
Working Groups
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.
The type references are now correctly generated using a wildcard. Pushed to master.
Closing all bugs that were set to RESOLVED before Neon.0