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

Bug 364692

Summary: [Xtend] warning about little type information
Product: [Tools] Xtend Reporter: Serano Colameo <serano.colameo>
Component: BacklogAssignee: Project Inbox <xtend-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.2.0Flags: sebastian.zarnekow: kepler+
Target Milestone: M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 376037    
Bug Blocks:    

Description Serano Colameo CLA 2011-11-24 04:47:16 EST
Build Identifier: Xtext 2.1.1.v201111141332

xtend:
	def dispatch getOperations(Facade f) {
		if (f == null || f.features.nullOrEmpty) return newArrayList
		return f.features.filter(typeof(Operation))
	}

	def dispatch getOperations(Mapper m) {
		if (m == null || m.features.nullOrEmpty) return newArrayList
		return m.features.filter(typeof(Operation))
	}

generated java:

  public Iterable<? extends Object> getOperations(final StructuralFeature f) {
    if (f instanceof Facade) {
      return _getOperations((Facade)f);
    } else if (f instanceof Mapper) {
      return _getOperations((Mapper)f);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(f).toString());
    }
  }
  protected Iterable<? extends Object> _getOperations(final Facade f) {
      boolean _operator_or = false;
      boolean _operator_equals = ObjectExtensions.operator_equals(f, null);
....

=> BUG:  protected Object _getOperations(final Mapper m) {
      boolean _operator_or = false;
      boolean _operator_equals = ObjectExtensions.operator_equals(m, null);
      if (_operator_equals) {
        _operator_or = true;

~serano

Reproducible: Always

Steps to Reproduce:
1. see details (=> BUG)
2.
3.
Comment 1 Serano Colameo CLA 2011-11-24 04:49:28 EST
workaround is to explicitely define a return type (Iterable<Operation>)

	def dispatch Iterable<Operation> getOperations(Facade f) {
		if (f == null || f.features.nullOrEmpty) return newArrayList
		return f.features.filter(typeof(Operation))
	}

	def dispatch  Iterable<Operation> getOperations(Mapper m) {
		if (m == null || m.features.nullOrEmpty) return newArrayList
		return m.features.filter(typeof(Operation))
	}

regards
serano
Comment 2 Sven Efftinge CLA 2011-11-24 04:56:19 EST
newArrayList is not parameterized with any type argument. So it defaults to ?.

You could either provide more type information in the return type or have an explicit type argument:

  return <Operation>newArrayList

We might want to add a warning if that little type information is available.
As soon as we have means to suppress or deactivate them again :-)
Comment 3 Sebastian Zarnekow CLA 2013-02-28 10:11:55 EST
Fixed with new type system.
Comment 4 Eclipse Webmaster CLA 2017-10-31 11:06:33 EDT
Requested via bug 522520.

-M.
Comment 5 Eclipse Webmaster CLA 2017-10-31 11:17:55 EDT
Requested via bug 522520.

-M.