eclipse-xtext / eclipse-xtext/xtext

Invalid default method multi-inheritance.

Open
#2,296 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

Let the following Xtend code:

class TestMultiInheritance<T> extends AbstractCollection<T> implements Set<T> {
	
	override iterator() {
		spliterator
                null
	}
	
	override size() {
               0
	}
	
}

The Xtend compiler generates the error "The type TestMultiInheritance inherits multiple implementations of the method spliterator() from Iterable and Set."

However, the equivalent Java code is compiling:

public class TestMultiInheritance<T extends Object> extends AbstractCollection<T> implements Set<T> {
  public Iterator<T> iterator() {
    this.spliterator();
    return null;
  }
  
  public int size() {
    return 0;
  }
}

The spliteraor function is defined in the Iterable and Set interfaces with different code. The Java compiler takes the default implementation from Set because is it the closest definition from the call in the type hierarchy.

Is a feature of Xtend to fail in this case? Or should Xtend be fixed in order to have a similar behavior as the Java compiler?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Xtend compiler handling of default methods for the reported TestMultiInheritance example, then compare its resolution with the equivalent Java code. Reproduce the multiple-inheritance error and determine whether the generated behavior should select Set's closer spliterator implementation, with a regression test covering the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.