Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345820 - [xtend] erroneous wildcard generated
Summary: [xtend] erroneous wildcard generated
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: RC1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-14 15:13 EDT by Knut Wannheden CLA
Modified: 2017-09-19 18:04 EDT (History)
1 user (show)

See Also:
sven.efftinge: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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