Bug 140569 - [1.5][compiler] Ambiguous conversion from generic to parameterized/raw type confuses Eclipse's way of resolving unresolved binary references
Summary: [1.5][compiler] Ambiguous conversion from generic to parameterized/raw type c...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-08 10:24 EDT by Tobias Riemenschneider CLA
Modified: 2006-05-11 22:11 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch (973 bytes, patch)
2006-05-11 05:55 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Riemenschneider CLA 2006-05-08 10:24:09 EDT
This bug report is closely conntected with bug 137203.

3.2RC2 and 3.2RC3 now resolves the unresolved binary reference mentioned in bug 137203 correctly, but when extracting the concerned method definition to a third file, the change from the method's (unnecessary) parameterized argument type to the non-parameterized argument type as well as any change to the classes ExtendedOuter and Worker results in a compile time error that only disappears when the enclosing project is rebuilt.

Guess the following scenario
> Outer.java >>>
public class Outer<O> {
  public class Inner {}
}
< Outer.java <<<
> ExtendedOuter.java >>>
public class ExtendedOuter<E> extends Outer<E> {
  public class ExtendedInner extends Inner {
    public void method() {
      Worker.method(this);
    }
  }
}
< ExtendedOuter.java <<<
> Worker.java >>>
public class Worker {
  public static void method(Outer.Inner i) {}
}
< Worker.java <<<
Every time ExtendedOuter or Worker is changed, e.g., by adding a field or method declaration, the described compile time error is introduced to ExtendedOuter. The same happens when changing the method definition in Worker to
  public static void method(Outer<?>.Inner i) {}
and back again.
Comment 1 Olivier Thomann CLA 2006-05-08 10:29:42 EDT
Reproduced with RC3.
Comment 2 Kent Johnson CLA 2006-05-08 14:26:31 EDT
When compiled from source, the parameter to Worker.method(Outer.Inner) is a RAW type [Inner#RAW enclosingType Outer#RAW] and the message send's argument is a ParameterizedType [ExtendedInner extends Inner enclosing type : ExtendedOuter<E>]

But when Worker is picked up a class file, the method's parameter becomes a ParameterizedType [Inner enclosingType Outer<O>].

The problem appears to be in LookupEnvironment.convertToRawType()
Comment 3 Philipe Mulet CLA 2006-05-09 11:47:48 EDT
+1 for 3.2RC4
Comment 4 Philipe Mulet CLA 2006-05-09 12:36:40 EDT
Added regression test: GenericTypeTest#test0981 (disabled)
Comment 5 Philipe Mulet CLA 2006-05-10 16:45:35 EDT
Kent suggested addressing it with following change on LookupEnvironment:

ReferenceBinding getTypeFromCompoundName(char[][] compoundName, boolean isParameterized) {
	ReferenceBinding binding = getCachedType(compoundName);
	if (binding == null) {
		PackageBinding packageBinding = computePackageFrom(compoundName);
		binding = new UnresolvedReferenceBinding(compoundName, packageBinding);
		packageBinding.addType(binding);
	} else if (binding == TheNotFoundType) {
		problemReporter.isClassPathCorrect(compoundName, null);
		return null; // will not get here since the above error aborts the compilation
	} else if (!isParameterized) {
	    // check raw type, only for resolved types
        binding = (ReferenceBinding)convertUnresolvedBinaryToRawType(binding);
	}
	return binding;
}
Comment 6 Philipe Mulet CLA 2006-05-10 16:49:52 EDT
Post 3.2, we should revisit the separation between #convertToRawType and #convertUnresolvedBinaryToRawType. Should be only one, doing the latter; and implicit member references should be dealt with differently.
But this is more extensive.
Comment 7 Philipe Mulet CLA 2006-05-11 05:55:53 EDT
Created attachment 41090 [details]
Proposed patch

This is the minimal patch, which is mirroring what we do in other cases in similar situations. Just missed one sender.

Without the patch, we reject valid code.

Dani/Martin: pls cast your vote
Comment 8 Philipe Mulet CLA 2006-05-11 05:56:22 EDT
Also added: GenericTypeTest#test0982
Comment 9 Dani Megert CLA 2006-05-11 06:05:03 EDT
Patch looks good. Approving for 3.2 RC4.
Comment 10 Martin Aeschlimann CLA 2006-05-11 06:09:32 EDT
+1 for 3.2 RC4
Comment 11 Philipe Mulet CLA 2006-05-11 06:28:35 EDT
Fix released
Comment 12 Olivier Thomann CLA 2006-05-11 22:11:29 EDT
Verified with I20060511-2000 for 3.2RC4