Bug 231861 - [1.5][compiler] Generics: problem with partial generics
Summary: [1.5][compiler] Generics: problem with partial generics
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 RC2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 235460 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-05-13 12:58 EDT by Markus Milleder CLA
Modified: 2008-06-04 07:24 EDT (History)
5 users (show)

See Also:
kent_johnson: review+
maxime_daniel: review+


Attachments
2 Projects mentioned in step 1 showing the error. (5.69 KB, application/zip)
2008-05-13 12:58 EDT, Markus Milleder CLA
no flags Details
Possible solution (911 bytes, patch)
2008-05-15 17:21 EDT, Kent Johnson CLA
no flags Details | Diff
Proposed patch (4.39 KB, patch)
2008-05-16 06:37 EDT, Philipe Mulet CLA
no flags Details | Diff
Alternative to patch 2 (isomorphic) (9.08 KB, patch)
2008-05-16 11:03 EDT, Maxime Daniel CLA
no flags Details | Diff
Patch for suggested cleanup (post 3.4) (24.36 KB, patch)
2008-05-16 11:44 EDT, Philipe Mulet CLA
no flags Details | Diff
Patch for 3.3.x (10.62 KB, patch)
2008-05-16 11:49 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 Markus Milleder CLA 2008-05-13 12:58:20 EDT
Created attachment 99986 [details]
2 Projects mentioned in step 1 showing the error.

Build ID: (3.4M7) I20080502-0100

Steps To Reproduce:
1. Import the attached projects into a 3.4M3 or later workspace.
2. Watch an error about the method Person#put

This error does not happen with 3.3.2, and neither with javac from JDK 1.6.0_03.

It gets even weirder:
3. Uncomment the superfluous import of base.Value
4. Watch the error go away.

Even more weird:
5. Move the Person class into base.
6. Get the same error as in step 2
7. Add an import for base.Value (!)
8. Watch the error go away again.


More information:
This is a reduced testcase from a more elaborate framework.

I have tried this in a newly unpacked 3.4M7 SDK with a new workspace, to make sure it is not an interaction with the host of plugins I have in my normal installation.

I have tried each 3.4 Milestones, M2 works, M3 and later fail.

Fully generifying the Model class (using Value<?>) fixes the testcase, but is impossible in the full framework (too many dependent generifications that end in "capture#1 does not match capture#2" errors).

Please update the summary if you have better words.
Comment 1 Kent Johnson CLA 2008-05-15 16:57:31 EDT
Reduced the testcase to these 3 files:

package p;
interface Value<B> {}
public class BaseValue<B> implements Value<B> {}


package p;
public class Model {
  public java.util.Map<String, Value> map = new java.util.LinkedHashMap<String, Value>();
}


package p2;
public class Person extends p.Model {
	void test() {
		this.map.put("name", new p.BaseValue<String>());
	}
}


A full build compiles the case correctly, but an incremental change to p2.Person fails to initialize the field in the BinaryType Model correctly.

Instead of reading the type args for the field map as String and Value#RAW, we read them in as String and Unresolved Value, which becomes Value<B>
Comment 2 Kent Johnson CLA 2008-05-15 17:21:42 EDT
Created attachment 100553 [details]
Possible solution

Philippe - please take a look.
Comment 3 Philipe Mulet CLA 2008-05-16 06:07:10 EDT
The fix is near this area, but I think it would be rather on caller side. I think your change will cause raw conversion in places we do not want it (i.e. too many raw conversions instead of too little as in this bug).

Adopting.
Comment 4 Philipe Mulet CLA 2008-05-16 06:11:48 EDT
Added GenericTypeTest#test1330-1331.
Comment 5 Philipe Mulet CLA 2008-05-16 06:37:20 EDT
Created attachment 100620 [details]
Proposed patch

Small patch for 3.4. It is close to Kent's, except it moves the raw conversion on argument resolution, instead of forcing it down in the process (where it could still be required to not do - though from looking at the code, this path would not be used any longer).

Post 3.4, we should do some cleanup in this code.
Comment 6 Philipe Mulet CLA 2008-05-16 07:23:39 EDT
Kent - pls review patch for 3.4RC2
Maxime - pls review patch for 3.4RC2
Comment 7 Philipe Mulet CLA 2008-05-16 07:24:24 EDT
forgot to cc maxime.
Comment 8 Maxime Daniel CLA 2008-05-16 08:54:14 EDT
Looking at the code, I cannot see any way parameterizedType could be non-null or rank non-zero. If I'm right and your patch is correct and we can further simplify the code right away with no risk at all (making a try on my side). Moreover, if it holds true, that property would make your patch a bit more intrusive than Kent's.
(I may have missed something though. Let's discuss this face-to-face.)
Comment 9 Philipe Mulet CLA 2008-05-16 09:01:59 EDT
You got the idea for the cleanup. Also the 2 methods for resolving type on BinaryTypeBinding could be merged together, in the same pass. But this is not essential at this point.
Comment 10 Maxime Daniel CLA 2008-05-16 09:16:10 EDT
(In reply to comment #3)
> ... I
> think your change will cause raw conversion in places we do not want it (i.e.
> too many raw conversions instead of too little as in this bug).
As we know that the second fix is more intrusive than the first, do we have any doubt about this left? (I mean, do we believe we may cause too many raw conversions?)
Comment 11 Philipe Mulet CLA 2008-05-16 09:33:52 EDT
I do not think the 2nd patch is more intrusive than the first one. It guarantees that arguments are being resolved consistently to any other type for which a raw type conversion is to be applied.
It does not change the mechanics of the internal resolution to always ignore the parameterizedType... so if in this branch we were to invoke with proper parameterizedType, it wouldn't change the semantics.

Today, I do not believe Kent's patch was actually causing trouble, but in theory it could have disrupted other senders. So this is more about aesthetics in the patch.
Comment 12 Kent Johnson CLA 2008-05-16 09:52:30 EDT
either patch is fine with me
Comment 13 Maxime Daniel CLA 2008-05-16 10:54:21 EDT
The second patch is readily isomorphic with code that eliminates the two latest parameters (the only call that does not pass null, 0 is the recursive call in the static method itself). The first might be so, but I've not dug into a proof of this (involves checking whether or not we can ever have parameterizedType not null on BinaryTypeBinding line 132, knowing that we pass this for bindings which kind could be - unless we know otherwise - be GENERIC). In all cases, a patch without the parameters would leave us with simpler code (that may or may not have a different behavior than patch 1).
Comment 14 Maxime Daniel CLA 2008-05-16 11:02:02 EDT
As far as speeding things up is concerned, I'd consider that we can go with patch 2 and see how it fares, opening a fup bug for simplification that would reference this one. I'll attach a patch 3 that is isomorphic to patch 2 for further reference.
Comment 15 Maxime Daniel CLA 2008-05-16 11:03:37 EDT
Created attachment 100652 [details]
Alternative to patch 2 (isomorphic)
Comment 16 Philipe Mulet CLA 2008-05-16 11:10:43 EDT
Released for 3.4RC2.
(2nd patch which got reviewed)

Comment 17 Philipe Mulet CLA 2008-05-16 11:44:25 EDT
Created attachment 100659 [details]
Patch for suggested cleanup (post 3.4)
Comment 18 Philipe Mulet CLA 2008-05-16 11:49:46 EDT
Created attachment 100663 [details]
Patch for 3.3.x
Comment 19 Philipe Mulet CLA 2008-05-16 11:50:18 EDT
Released to 3.3.x maintenance stream.
Comment 20 Jerome Lanneluc CLA 2008-05-23 06:20:56 EDT
Verified for 3.4RC2 using I20080523-0100
Comment 21 Philipe Mulet CLA 2008-06-04 07:24:35 EDT
*** Bug 235460 has been marked as a duplicate of this bug. ***