Bug 79673 - [1.5] Wrong method binding
Summary: [1.5] Wrong method binding
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-29 11:25 EST by David Audel CLA
Modified: 2004-12-16 10:27 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Audel CLA 2004-11-29 11:25:55 EST
build I200411240800
1) create Test.java
public class Test {
  public <T2> void foo() {
  	
  }
}
class Test2 {
  void bar(Test var) {
    var.foo();
  }
}
2) compile

The resolved binding for "var.foo()" is a MethodBinding. It should be a
ParameterizedGenericMethodBinding.

With the following test case, the binding is a ParameterizedGenericMethodBinding.

public class Test {
  public <T2> T2 foo() {
     return null;
  }
}
class Test2 {
  void bar(Test var) {
    var.foo();
  }
}
Comment 1 David Audel CLA 2004-11-30 06:31:56 EST
Another strange binding.

public class Test {
  public <U> Test(U u) {
  }
  void bar() {
    new <String>Test(null){};
  }
}

The binding of "new <String>Test(null){}" is a MethodBinding instead of
ParameterizedGenericMethodBinding
Comment 2 Philipe Mulet CLA 2004-12-01 11:35:41 EST
Problem comes from the fact we picked an exact match.
Comment 3 Philipe Mulet CLA 2004-12-01 11:54:08 EST
First scenario comes from the fact that Scope#computeCompatibleMethod was
incorrectly optimizing out the scenario where signature thought it had no
mention of generics (though it still had type variables to substitute).

Comment 4 Philipe Mulet CLA 2004-12-01 11:55:00 EST
Note that this problem had no incidence on compiler functionning as the
signature did not contain any invalid information.
Comment 5 Philipe Mulet CLA 2004-12-01 11:59:44 EST
Other scenario works fine with correction, also checked:
public class X {
  public <U> X(Object o) {
  }
  void bar() {
    new X(null){};
  }
}

Fixed.
David - pls add regression tests using selections to expose binding natures.
Comment 6 David Audel CLA 2004-12-01 13:06:19 EST
tests ResolveTest1_5#test0058() and and test0060 updated.
Comment 7 Olivier Thomann CLA 2004-12-14 17:57:02 EST
Comment 1 doesn't use a ParameterizedGenericMethodBinding. It is still using a
MethodBinding.
Comment 8 Philipe Mulet CLA 2004-12-16 07:02:12 EST
I double checked that the offending binding in comment#1 is truly a
ParameterizedGenericMethodBinding.

Frederic - pls double check
Comment 9 Frederic Fusier CLA 2004-12-16 10:25:52 EST
Create test cases comment 0, comment 1 and comment 5 in self-hosting workspace
and use debugger in resolveType() method of MessageSend (comment 0) and
QualifiedAllocationExpression (comment 1 and comment 5).

I confirm that inheritedBinding is now well computed with this bug fix (ie. it
is a ParameterizedGenericMethodBiding for all these test cases).
Comment 10 Frederic Fusier CLA 2004-12-16 10:27:13 EST
Verified for 3.1 M4 using build I200412142000.

Note however, that even if inheritedBinding is well computed with this bug fix,
for comment 5 test case, it is not persisted in constructorCall.binding of
ConstructorDeclaration in anonymousType.methods array...

I'll open a new separated bug for this issue.