Bug 258798 - [1.5][compiler] Return type should be erased after unchecked conversion during inference
Summary: [1.5][compiler] Return type should be erased after unchecked conversion durin...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 117119 118273 231094 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-12-15 06:57 EST by Philipe Mulet CLA
Modified: 2009-01-27 05:34 EST (History)
5 users (show)

See Also:


Attachments
In progress patch (188.47 KB, patch)
2009-01-07 11:12 EST, Philipe Mulet CLA
no flags Details | Diff
Improved patch (190.27 KB, patch)
2009-01-07 12:07 EST, Philipe Mulet CLA
no flags Details | Diff
Better patch (192.77 KB, patch)
2009-01-08 04:34 EST, Philipe Mulet CLA
no flags Details | Diff
Better patch 2 (57.86 KB, patch)
2009-01-08 05:20 EST, Philipe Mulet CLA
no flags Details | Diff
Better patch 2 (206.39 KB, patch)
2009-01-08 11:26 EST, Philipe Mulet CLA
no flags Details | Diff
Final patch (220.70 KB, patch)
2009-01-08 16:09 EST, 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 Philipe Mulet CLA 2008-12-15 06:57:32 EST
Build 3.5M4

According to JLS 15.12.2.6 (2nd bullet), a method's return type should be erased after any unchecked conversion was necessary during type inference.

e.g.
class Foo<T> {}
public class X {
	public void test() {
		Integer i = m(new Foo<Foo<Integer>>(), new Foo());
	}
	public <T> T m(Foo<T> x, T t) {
		return t;
	}
}


should surface an error where the return type got erased:
   Type mismatch: cannot convert from Foo to Integer
instead of:
   Type mismatch: cannot convert from Foo<Integer> to Integer

Hence, an unchecked method invocation warning should be surfaced as well, which is missing today.
Comment 1 Philipe Mulet CLA 2008-12-18 06:28:58 EST
Added GenericTypeTest#test1429-1431
Comment 2 Philipe Mulet CLA 2008-12-18 06:33:17 EST
also see bug 231094
Comment 3 Philipe Mulet CLA 2009-01-07 11:12:22 EST
Created attachment 121819 [details]
In progress patch

still failing some AmbiguousMethodTest:

test011a(org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest)
test011b(org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest)



RunAllJDTCoreTests
org.eclipse.jdt.core.tests.RunAllJDTCoreTests
org.eclipse.jdt.core.tests.RunAllCompilerTests
org.eclipse.jdt.core.tests.RunCompilerTests
org.eclipse.jdt.core.tests.compiler.regression.TestAll
1.5
org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest
test011a(org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest)

                  
                  junit.framework.ComparisonFailure: Unexpected failure.
----------- Expected ------------

------------ but was ------------
----------\n
1. ERROR in Combined.java (at line 4)\r\n
	void pickOne(Combined<Integer,Integer> c) throws ExOne { c.pickOne("test"); }\r\n
	                                                           ^^^^^^^\n
The method pickOne(String) is ambiguous for the type Combined<Integer,Integer>\n
----------\n

--------- Difference is ----------
 expected:<[]> but was:<[----------\n
1. ERROR in Combined.java (at line 4)\r\n
	void pickOne(Combined<Integer,Integer> c) throws ExOne { c.pickOne("test"); }\r\n
	                                                           ^^^^^^^\n
The method pickOne(String) is ambiguous for the type Combined<Integer,Integer>\n
----------\n
]>
	at org.eclipse.jdt.core.tests.junit.extension.TestCase.assertStringEquals(TestCase.java:230)
	at org.eclipse.jdt.core.tests.junit.extension.TestCase.assertEquals(TestCase.java:206)
	at org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.runTest(AbstractRegressionTest.java:2152)
	at org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.runConformTest(AbstractRegressionTest.java:1145)
	at org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest.test011a(AmbiguousMethodTest.java:476)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.core.tests.util.CompilerTestSetup.run(CompilerTestSetup.java:55)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
	at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:195)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:366)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:550)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:505)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1237)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1213)

test011b(org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest)

                  
                  junit.framework.ComparisonFailure: Invalid problem log .
----------- Expected ------------
----------\n
1. WARNING in Test1.java (at line 4)\n
	void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) "test"); }\n
	                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n
Type safety: Unchecked invocation pickOne(Comparable) of the generic method pickOne(T) of type Test1<Integer,Integer>\n
----------\n
2. WARNING in Test1.java (at line 4)\n
	void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) "test"); }\n
	                                                                  ^^^^^^^^^^\n
Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n
----------\n

------------ but was ------------
----------\n
1. ERROR in Test1.java (at line 4)\n
	void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) "test"); }\n
	                                                         ^^^^^^^\n
The method pickOne(Comparable) is ambiguous for the type Test1<Integer,Integer>\n
----------\n
2. WARNING in Test1.java (at line 4)\n
	void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) "test"); }\n
	                                                                  ^^^^^^^^^^\n
Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n
----------\n

--------- Difference is ----------
 expected:<----------\n
1. [WARNING in Test1.java (at line 4)\n
	void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) "test"); }\n
	                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n
Type safety: Unchecked invocation pickOne(Comparable) of the generic method pickOne(T) of] type Test1<Integer,...> but was:<----------\n
1. [ERROR in Test1.java (at line 4)\n
	void pickOne2(Test1<Integer,Integer> c) throws ExOne { c.pickOne((Comparable) "test"); }\n
	                                                         ^^^^^^^\n
The method pickOne(Comparable) is ambiguous for the] type Test1<Integer,...>
	at org.eclipse.jdt.core.tests.junit.extension.TestCase.assertStringEquals(TestCase.java:230)
	at org.eclipse.jdt.core.tests.junit.extension.TestCase.assertEquals(TestCase.java:206)
	at org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.checkCompilerLog(AbstractRegressionTest.java:869)
	at org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.runTest(AbstractRegressionTest.java:2138)
	at org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.runNegativeTest(AbstractRegressionTest.java:1756)
	at org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest.test011b(AmbiguousMethodTest.java:495)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.core.tests.util.CompilerTestSetup.run(CompilerTestSetup.java:55)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
	at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:195)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:366)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:550)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:505)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1237)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1213)
Comment 4 Philipe Mulet CLA 2009-01-07 12:07:56 EST
Created attachment 121827 [details]
Improved patch

Passes a Javadoc test (which failed with previous patch)
Comment 5 Philipe Mulet CLA 2009-01-08 04:33:38 EST
cc'ing Frederic for Javadoc failure (Frederic pls file a separate bug for situations which did not work and will be fixed along with changes made for this bug) e.g.:
- Should warn missing tag (ko)

import java.util.*;
public class X<T> {
	X(ArrayList<T> alt) {}
}
class Y<U> extends X<U> {
	/** @see X#X(ArrayList) */
	Y(List<U> lu) { super(null); }
}


Comment 6 Philipe Mulet CLA 2009-01-08 04:34:14 EST
Created attachment 121927 [details]
Better patch
Comment 7 Philipe Mulet CLA 2009-01-08 05:16:27 EST
Added GenericTypeTest#test1429-1430, test1432-1439 
Comment 8 Philipe Mulet CLA 2009-01-08 05:20:01 EST
Created attachment 121929 [details]
Better patch 2

Still having issues with method ambiguities.
Now also erase thrown exception when unchecked invocation (as mandated by 15.12.2.6)
Comment 9 Philipe Mulet CLA 2009-01-08 11:26:16 EST
Created attachment 121969 [details]
Better patch 2

previous patch was corrupted
Comment 10 Philipe Mulet CLA 2009-01-08 11:33:59 EST
*** Bug 231094 has been marked as a duplicate of this bug. ***
Comment 11 Philipe Mulet CLA 2009-01-08 16:05:39 EST
*** Bug 118273 has been marked as a duplicate of this bug. ***
Comment 12 Philipe Mulet CLA 2009-01-08 16:07:55 EST
*** Bug 117119 has been marked as a duplicate of this bug. ***
Comment 13 Philipe Mulet CLA 2009-01-08 16:09:59 EST
Created attachment 122013 [details]
Final patch
Comment 14 Philipe Mulet CLA 2009-01-08 16:10:27 EST
Released for 3.5M5.
Fixed
Comment 15 Frederic Fusier CLA 2009-01-09 09:40:55 EST
Added JavadocBugsTest.testBug258798_*
Comment 16 Frederic Fusier CLA 2009-01-27 05:34:14 EST
Verified for 3.5M5 using build I20090127-0100.