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

Bug 345820

Summary: [xtend] erroneous wildcard generated
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: RC1   
Hardware: All   
OS: All   
Whiteboard:

Description Knut Wannheden CLA 2011-05-14 15:13:15 EDT
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;
  }
Comment 1 Sven Efftinge CLA 2011-05-15 04:15:13 EDT
We need to validate that wildcards are generally not allowed as type arguments for method or constructor invocations.
Comment 2 Sven Efftinge CLA 2011-05-15 09:00:04 EDT
I have added a check for wildcards being not allowed at that position.
Comment 3 Karsten Thoms CLA 2017-09-19 17:53:19 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 4 Karsten Thoms CLA 2017-09-19 18:04:03 EDT
Closing all bugs that were set to RESOLVED before Neon.0