Bug 121369 - [1.5][compiler] Eclipse successfully compiles buggy code
Summary: [1.5][compiler] Eclipse successfully compiles buggy code
Status: VERIFIED NOT_ECLIPSE
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 156765 158531 174447 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-12-19 03:41 EST by Ingo R. Homann CLA
Modified: 2011-01-25 09:29 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ingo R. Homann CLA 2005-12-19 03:41:27 EST
This is a bug in the type inferrer. It seems to be related to bug #114087.

The following code can be compiled by Eclipse 3.2M4:

class Foo
{

  static <T, U extends java.util.List<T>> void foo()
  {
    return;
  }

}

public class EclipseCompilerBug
{

  {
    Foo.foo();
  }

}

javac complains with the following error:

de\ingo_homann\test\EclipseCompilerBug.java:20: incompatible types; inferred type argument(s) java.lang.Object,java.lang.Object do not conform to bounds of type
 variable(s) T,U
found   : <T,U>void
required: void
    Foo.foo();
Comment 1 Olivier Thomann CLA 2005-12-19 12:59:51 EST
Don't set the target milestone. This indicates in which build the problem is fixed, not in which build the problem occurs.
Comment 2 Philipe Mulet CLA 2006-01-05 09:06:31 EST
1. I wonder if this isn't a bug in javac
2. When inferring, we find: <Object,List<T>>, where I would expect: <Object,List<Object>>
Comment 3 Philipe Mulet CLA 2006-01-05 11:25:28 EST
15.2.2.8: 
No expected return type (using assignment conversion).
Additional constraint from type variable bounds:
  List<T>  >>  U

15.2.2.7: A >> F 
  where A: List<T>, F: U
  
First bullet says, if F = Tj --> Tj <: A is implied (p.457)
   i.e. U <: List<T>

Constraints are resolved, see p.466 (15.2.2.8), and 
        U = glb(List<T>) --> U = List<T>

At the end, T remains unresolved; and thus get inferred to be Object.
(the spec doesn't explicitly tell about need to substitute U inferred
value List<T>, but presumably this is an omission).

In the end, it should yield:
   T = Object,
   U = List<Object>
Comment 4 Philipe Mulet CLA 2006-01-05 11:51:24 EST
In order to notice issue between List<T> and List<Object>, here is a testcase:
class Foo {
	static <T, U extends java.util.List<T>> U foo() {
		return null;
	}
}

public class X {
	{
		String s = (String) Foo.foo();
	}
}
Comment 5 Philipe Mulet CLA 2006-01-05 12:07:27 EST
Interestingly, the following variation doesn't seem handled well either by javac (replace List<T> with List<U>):
class Foo {
	static <T, U extends java.util.List<U>> U foo() {
		return null;
	}
}
public class X {
	{
		String s = (String) Foo.foo();
	}
}

but this time, it goes further in inference, failing only the bound check in the end; which makes me feel it has holes in this area.

Now, our compiler doesn't quite handle this scenario either; yielding U = List<List<U>> which isn't much better.

I feel the spec is incomplete when inference brings back types referring to original type variables (List<T> or List<U>). Either these are tolerated providing they are not resolving self references (List<T>) or they are all rejected for simplicity.
Comment 6 Philipe Mulet CLA 2006-01-06 09:06:00 EST
Javac and spec bugs got confirmed, they should be:
compiler: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6369605
spec:     http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6369608
Comment 7 Philipe Mulet CLA 2006-04-20 10:51:38 EDT
defer post 3.2
Comment 8 Philipe Mulet CLA 2006-09-14 05:12:42 EDT
Reviving
Comment 9 Philipe Mulet CLA 2006-09-14 05:52:11 EDT
*** Bug 156765 has been marked as a duplicate of this bug. ***
Comment 10 Philipe Mulet CLA 2006-09-15 03:42:35 EDT
*** Bug 156765 has been marked as a duplicate of this bug. ***
Comment 11 Philipe Mulet CLA 2006-09-25 11:52:18 EDT
*** Bug 158531 has been marked as a duplicate of this bug. ***
Comment 12 Philipe Mulet CLA 2008-04-21 07:31:15 EDT
*** Bug 174447 has been marked as a duplicate of this bug. ***
Comment 13 Philipe Mulet CLA 2008-09-03 04:55:28 EDT
Regression tests are:
GenericTypeTest#test0880-0883
Comment 14 Olivier Thomann CLA 2010-10-29 13:41:58 EDT
javac 1.7 doesn't report any error.
Should not this be closed as NOT_ECLIPSE or INVALID?
Comment 15 Srikanth Sankaran CLA 2011-01-11 04:13:31 EST
(In reply to comment #14)
> javac 1.7 doesn't report any error.
> Should not this be closed as NOT_ECLIPSE or INVALID?

(In reply to comment #6)
> Javac and spec bugs got confirmed, they should be:
> compiler: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6369605
> spec:     http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6369608

Indeed. javac fixed the compiler bug in 7(b109). Resolving as
NOT_ECLIPSE.
Comment 16 Olivier Thomann CLA 2011-01-25 09:29:37 EST
Verified for 3.7M5 using I20110124-1800