Bug 204534 - [1.5][compiler] Annoying consequence of method verification problem
Summary: [1.5][compiler] Annoying consequence of method verification problem
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M3   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-25 07:41 EDT by Philipe Mulet CLA
Modified: 2007-10-29 06:22 EDT (History)
0 users

See Also:


Attachments
Proposed patch (1.49 KB, patch)
2007-09-25 13:41 EDT, Kent Johnson CLA
no flags Details | Diff
Proposed patch with testcase (4.90 KB, patch)
2007-09-26 15:08 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 Philipe Mulet CLA 2007-09-25 07:41:09 EDT
Build 3.4M2

On following example, due to method redundant definitions, the compiler reports unresolved references to type parameter R within method bodies.

From the inside, the offending method binding should be preserved when diving into its body resolution.

In presence of duplicates, it also seems like we should keep one binding to minimize incidence from the outside.

public class X {
	public static <S, T extends Comparable<S>, R extends S & T> R max(T arg1, S arg2) {
		return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);
	}

	public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max(T arg1, S arg2) {
		return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);
	}

	public static <T extends Comparable<S>, S, R extends Comparable<S>> R max(T arg1, S arg2) {
		return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);
	}

	public static void main(String[] args) {
	}
}
Comment 1 Philipe Mulet CLA 2007-09-25 07:43:36 EDT
Errors currently reported. Observe (3) and (6) secondary errors which shouldn't appear.

----------
1. ERROR in X.java (at line 2)
	public static <S, T extends Comparable<S>, R extends S & T> R max(T arg1, S arg2) {
	                                                         ^
Cannot specify any additional bound T when first bound is a type parameter
----------
2. ERROR in X.java (at line 2)
	public static <S, T extends Comparable<S>, R extends S & T> R max(T arg1, S arg2) {
	                                                              ^^^^^^^^^^^^^^^^^^^
Method max(T, S) has the same erasure max(Comparable<T>, Object) as another method in type X
----------
3. ERROR in X.java (at line 3)
	return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);
	        ^
R cannot be resolved to a type
----------
4. ERROR in X.java (at line 6)
	public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max(T arg1, S arg2) {
	                                                         ^^^^^^^^^^
Cannot specify any additional bound Comparable<S> when first bound is a type parameter
----------
5. ERROR in X.java (at line 6)
	public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max(T arg1, S arg2) {
	                                                                          ^^^^^^^^^^^^^^^^^^^
Method max(T, S) has the same erasure max(Comparable<T>, Object) as another method in type X
----------
6. ERROR in X.java (at line 7)
	return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);
	        ^
R cannot be resolved to a type
----------
7. WARNING in X.java (at line 11)
	return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type safety: Unchecked cast from Object to R
----------
Comment 2 Philipe Mulet CLA 2007-09-25 07:45:48 EDT
Added GenericTypeTest#test1181
Comment 3 Kent Johnson CLA 2007-09-25 13:41:41 EDT
Created attachment 79152 [details]
Proposed patch

The patch matches the type variable name against the method declaration's type parameter nodes instead of relying on the method's binding.
Comment 4 Kent Johnson CLA 2007-09-26 15:08:27 EDT
Created attachment 79233 [details]
Proposed patch with testcase

This patch only uses the method declaration's nodes when the binding isn't set.

fixed up GenericTypeTest test1181()
Comment 5 Kent Johnson CLA 2007-09-26 15:10:34 EDT
Released into HEAD
Comment 6 Frederic Fusier CLA 2007-10-29 06:22:11 EDT
Verified for 3.4M3 using I20071029-0010 build.