Community
Participate
Working Groups
The following Xtend2 snippet: def foo() { var x = <?> newArrayList('foo', 'bar') x = newArrayList(42) } compiles to: public ArrayList<?> foo() { ArrayList<?> _xblockexpression = null; { ArrayList<?> _newArrayList = CollectionLiterals.<?>newArrayList("foo", "bar"); // COMPILE ERROR ArrayList<?> x = _newArrayList; ArrayList<Integer> _newArrayList_1 = CollectionLiterals.<Integer>newArrayList(((Integer)42)); ArrayList<?> _x = x = _newArrayList_1; _xblockexpression = (_x); } return _xblockexpression; } This results in the Java compile error "Wildcard is not allowed at this location". The same is true for a "more sensible" use case: def foo() { var x = <? extends CharSequence> newArrayList('foo', 'bar') x = newArrayList(new StringBuilder('baz')) } which compiles to: public ArrayList<? extends CharSequence> foo() { ArrayList<? extends CharSequence> _xblockexpression = null; { ArrayList<? extends CharSequence> _newArrayList = CollectionLiterals.<? extends CharSequence>newArrayList("foo", "bar"); ArrayList<? extends CharSequence> x = _newArrayList; StringBuilder _stringBuilder = new StringBuilder("baz"); ArrayList<StringBuilder> _newArrayList_1 = CollectionLiterals.<StringBuilder>newArrayList(_stringBuilder); ArrayList<? extends CharSequence> _x = x = _newArrayList_1; _xblockexpression = (_x); } return _xblockexpression; }
We need to validate that wildcards are generally not allowed as type arguments for method or constructor invocations.
I have added a check for wildcards being not allowed at that position.
Closing all bugs that were set to RESOLVED before Neon.0