Bug 223986 - Invalid incompatible return type error
Summary: Invalid incompatible return type error
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-25 17:30 EDT by Divyanshu Sharma CLA
Modified: 2008-04-29 05:28 EDT (History)
3 users (show)

See Also:


Attachments
Test case (3.06 KB, application/x-zip-compressed)
2008-03-26 09:31 EDT, Divyanshu Sharma CLA
no flags Details
Proposed patch with testcase (7.17 KB, patch)
2008-03-27 14:08 EDT, Kent Johnson CLA
no flags Details | Diff
Updated patch (7.16 KB, patch)
2008-03-27 15:33 EDT, Kent Johnson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Divyanshu Sharma CLA 2008-03-25 17:30:28 EDT
Build ID: M20080221-1800

Steps To Reproduce:
Getting compilation error while compiling below mentioned test case code. However, it compiles fine with Sun JDK 1.5.0_06. 

Compilation error:

The return type is incompatible with SuperTypeExtend.plus(SubOne), SubOne.plus(SubOne)	taxems/source/test/test/impl	SubSubOneImpl.java	line 3	

----------------------------------------

package test.impl;

import test.intf.SubTwo;

public abstract class SubOneImpl extends SuperTypeExtendImpl implements test.intf.SubOne
{
    // FloatAttribute operands

    public SubOneImpl plus(test.intf.SubOne attribute)
    {
        throw new RuntimeException("foo");
    }

    // DoubleAttribute operands

    public SubTwoImpl plus(SubTwo attribute)
    {
        throw new RuntimeException("foo");
    }
}

--------------------------------------------

package test.impl;

public abstract class SubSubOneImpl extends SubOneImpl
{
}

--------------------------------------

package test.impl;

import test.intf.SubOne;

public abstract class SubTwoImpl extends SuperTypeExtendImpl implements test.intf.SubTwo
{
    // FloatAttribute operands

    public SubTwoImpl plus(SubOne attribute)
    {
        throw new RuntimeException("foo");
    }

    // DoubleAttribute operands

    public SubTwoImpl plus(test.intf.SubTwo attribute)
    {
        throw new RuntimeException("foo");
    }
}


----------------------------------------


package test.impl;

import test.intf.SubOne;
import test.intf.SubTwo;

public interface SuperTypeExtend extends test.intf.SuperType
{
    public SuperTypeExtend plus(SubOne addend);
    public SuperTypeExtend plus(SubTwo addend);
}

---------------------------------------------------


package test.impl;

public abstract class SuperTypeExtendImpl implements SuperTypeExtend
{
}

---------------------------------------------------------

More information:
Comment 1 Olivier Thomann CLA 2008-03-25 18:51:43 EDT
The test case is incomplete. The package test.intf is missing.
What are your compiler settings for your project ?
Did you set the compliance to be 1.5 ?
Comment 2 Philipe Mulet CLA 2008-03-26 06:44:09 EDT
Need more info. 
Comment 3 Divyanshu Sharma CLA 2008-03-26 09:31:06 EDT
Created attachment 93581 [details]
Test case

Apologies for missing package. Compiler Compliance level set to 5.0

Please find below the missing package interfaces:

-----------------------------------------------------------------------

package test.intf;

public interface SubOne<Owner> extends SuperType<Owner>
{
    public SubOne<Owner> plus(SubOne addend);
    public SubTwo<Owner> plus(SubTwo addend);
}

-------------------------------------------------------------------------


package test.intf;

public interface SubTwo<Owner> extends SuperType<Owner>
{
    public SubTwo<Owner> plus(SubOne addend);
    public SubTwo<Owner> plus(SubTwo addend);
}


--------------------------------------------------------------------------


package test.intf;

public interface SuperType<Owner>
{
    public SuperType<Owner> plus(SubOne addend);
    public SuperType<Owner> plus(SubTwo addend);
}

---------------------------------------------------------------------------
Comment 4 Philipe Mulet CLA 2008-03-27 07:09:25 EDT
Reproduced with HEAD.

We issue 2 complaints against SubSubOneImpl

----------
1. ERROR in test\impl\SubSubOneImpl.java (at line 3)
        public abstract class SubSubOneImpl extends SubOneImpl {
                              ^^^^^^^^^^^^^
The return type is incompatible with SuperTypeExtend.plus(SubTwo), SubOne.plus(SubTwo)
----------
2. ERROR in test\impl\SubSubOneImpl.java (at line 3)
        public abstract class SubSubOneImpl extends SubOneImpl {
                              ^^^^^^^^^^^^^
The return type is incompatible with SuperTypeExtend.plus(SubOne), SubOne.plus(SubOne)
----------
Comment 5 Philipe Mulet CLA 2008-03-27 08:00:20 EDT
Added (disabled) MethodVerifierTest#_test153
Comment 6 Philipe Mulet CLA 2008-03-27 08:04:51 EDT
Kent - putting all in one file makes the problem go away... !?

abstract class SubOneImpl extends SuperTypeExtendImpl implements test.intf.SubOne {
	public SubOneImpl plus(test.intf.SubOne attribute) {
		throw new RuntimeException("foo");
	}

	public SubTwoImpl plus(SubTwo attribute) {
		throw new RuntimeException("foo");
	}
}

abstract class SubSubOneImpl extends SubOneImpl {
}

abstract class SubTwoImpl extends SuperTypeExtendImpl implements test.intf.SubTwo {
	public SubTwoImpl plus(SubOne attribute) {
		throw new RuntimeException("foo");
	}

	public SubTwoImpl plus(test.intf.SubTwo attribute) {
		throw new RuntimeException("foo");
	}
}

interface SuperTypeExtend extends test.intf.SuperType {
	public SuperTypeExtend plus(SubOne addend);

	public SuperTypeExtend plus(SubTwo addend);
}

abstract class SuperTypeExtendImpl implements SuperTypeExtend {
}

interface SubOne<Owner> extends SuperType<Owner> {
	public SubOne<Owner> plus(SubOne addend);

	public SubTwo<Owner> plus(SubTwo addend);
}

interface SubTwo<Owner> extends SuperType<Owner> {
	public SubTwo<Owner> plus(SubOne addend);

	public SubTwo<Owner> plus(SubTwo addend);
}

interface SuperType<Owner> {
	public SuperType<Owner> plus(SubOne addend);

	public SuperType<Owner> plus(SubTwo addend);
}
Comment 7 Philipe Mulet CLA 2008-03-27 09:03:39 EDT
Ignore my last comment, I had left some qualifier in some type names, all in one file does reproduce the issue.


abstract class SubOneImpl extends SuperTypeExtendImpl implements SubOne {
	public SubOneImpl plus(SubOne attribute) {
		throw new RuntimeException("foo");
	}
	public SubTwoImpl plus(SubTwo attribute) {
		throw new RuntimeException("foo");
	}
}

abstract class SubSubOneImpl extends SubOneImpl {
}

abstract class SubTwoImpl extends SuperTypeExtendImpl implements SubTwo {
	public SubTwoImpl plus(SubOne attribute) {
		throw new RuntimeException("foo");
	}
	public SubTwoImpl plus(SubTwo attribute) {
		throw new RuntimeException("foo");
	}
}

interface SuperTypeExtend extends SuperType {
	public SuperTypeExtend plus(SubOne addend);
	public SuperTypeExtend plus(SubTwo addend);
}

abstract class SuperTypeExtendImpl implements SuperTypeExtend {
}

interface SubOne<Owner> extends SuperType<Owner> {
	public SubOne<Owner> plus(SubOne addend);
	public SubTwo<Owner> plus(SubTwo addend);
}

interface SubTwo<Owner> extends SuperType<Owner> {
	public SubTwo<Owner> plus(SubOne addend);
	public SubTwo<Owner> plus(SubTwo addend);
}

interface SuperType<Owner> {
	public SuperType<Owner> plus(SubOne addend);
	public SuperType<Owner> plus(SubTwo addend);
}
Comment 8 Philipe Mulet CLA 2008-03-27 10:53:53 EDT
Simpler testcase:
import java.io.Serializable;
interface AFoo { 
	Serializable foo();
	Serializable bar();
}
interface BFoo { 
	Cloneable foo(); 
	Cloneable bar(); 
}
interface C extends Serializable, Cloneable {}
class Root {
	public C foo() { return null; }
}
public abstract class X extends Root implements AFoo, BFoo {
}

javac reports 1 error (against #bar()), we report 2 (#bar() and #foo()).
Method verifier seems to go too deep in inherited method chain. It should stop investigation when noticing super method definition Root#foo(). If such a method got defined, then it supercedes the other ones if it looks like an implementation for these.
Comment 9 Philipe Mulet CLA 2008-03-27 10:58:21 EDT
Also added MethodVerifierTest#test154-158 (some disabled)
Comment 10 Kent Johnson CLA 2008-03-27 14:08:47 EDT
Created attachment 93830 [details]
Proposed patch with testcase
Comment 11 Kent Johnson CLA 2008-03-27 15:33:12 EDT
Created attachment 93854 [details]
Updated patch
Comment 12 Kent Johnson CLA 2008-04-14 13:22:04 EDT
Released into HEAD for 3.4M7
Comment 13 David Audel CLA 2008-04-29 05:28:42 EDT
Verified for 3.4M7 using I20080427-2000