Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 80715 - ITypeBinding#isAssignmentCompatible(..) doesn't work across binding resolvers
Summary: ITypeBinding#isAssignmentCompatible(..) doesn't work across binding resolvers
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 120471 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-10 13:28 EST by Markus Keller CLA
Modified: 2010-08-11 06:15 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2004-12-10 13:28:38 EST
I200412081200

We tried to replace our TypeRules#canAssign(..) method by
ITypeBinding#isAssignmentCompatible(..). This resulted in many test failures in
UseSupertypeWherePossibleTests and ExtractInterfaceTests. The reason is that
isAssignmentCompatible(..) doesn't work corrctly with bindings that are
isEqualTo(..), but not identical.

E.g. in UseSupertypeWherePossibleTests.testNew7(), we call
isAssignmentCompatible with two type bindings for the same type p.B (isEqualTo
== true, but not identical) and get false as result.

We reverted TypeRules to our old implementation in HEAD.
Comment 1 Olivier Thomann CLA 2004-12-10 13:41:33 EST
Could you provide a test case?
Comment 2 Markus Keller CLA 2004-12-10 13:50:30 EST
package p;
class A implements I {
	public void m(){}
	void f(){
		A a= new A();
		a.m();
	}
}

interface I {
	void m();
}
---------------------------

- Select type A and choose Refactor > Use Supertype Where Possible
- select I and press OK
=> With jdt.ui from HEAD or from I200412081200: correctly rewrites type of a to I.

- change body of TypeRules#canAssign(ITypeBinding, ITypeBinding) to

    return typeToAssign.isAssignmentCompatible(definedType);

=> "The refactoring does not change any source code".
Comment 3 Jerome Lanneluc CLA 2004-12-13 04:32:49 EST
Markus, that is the expected behavior. Both bindings have to come from the same
batch. I will update the spec to clarify this.
Comment 4 Dirk Baeumer CLA 2004-12-13 06:09:55 EST
Jerome, but then the API isn't very useful for us. Not all the binding we have
are from the same batch. Ensuring this will be a major rewrite and not always
possible since we reuse the cached AST from the editor in various cases which
will be definitelly from a different batch.
Comment 5 Dirk Baeumer CLA 2004-12-13 06:11:18 EST
Why do the bindings have to be from the same batch ?
Comment 6 Dirk Baeumer CLA 2004-12-13 06:16:34 EST
May be IBinding#isEqualTo(...) can help here.
Comment 7 Philipe Mulet CLA 2005-01-10 10:53:19 EST
Leveraging binding comparisons to work across contexts is quite hard to achieve;
since binding rules are relying on identities (on compiler side) and we do not
want to duplicate all algorithms.

We could remove #isEqualsTo (btw: it feels like it should have be #equals). And
rather make it clear that comparisons are meant to work on bindings within same
context. 
Now we should investigate offerring instead a way to reobtain a binding in a
given context (from a possibly remote one):
- surface the binding context
- allow it to query for a 'relocalized' binding
Comment 8 Philipe Mulet CLA 2005-06-10 04:57:19 EDT
Defer
Comment 9 Denis Roy CLA 2009-08-30 02:24:35 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.
Comment 10 Markus Keller CLA 2010-08-11 06:14:27 EDT
The right way to solve this problem is to offer an open bindings environment (bug 150657), where ASTs/bindings can be created on demand in the same environment.
Comment 11 Markus Keller CLA 2010-08-11 06:15:12 EDT
*** Bug 120471 has been marked as a duplicate of this bug. ***