Bug 528970 - [1.8][inference] subtype constraint should ask isSubtypeOf(), not isCompatiblewith() (?)
Summary: [1.8][inference] subtype constraint should ask isSubtypeOf(), not isCompatibl...
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7.1a   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on: 448793
Blocks: 536585 540208 564617
  Show dependency tree
 
Reported: 2017-12-19 13:04 EST by Stephan Herrmann CLA
Modified: 2022-11-12 17:17 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2017-12-19 13:04:20 EST
See this SO thread: https://stackoverflow.com/questions/47662493/eclipse-ecj-accepts-this-code-javac-doesnt-who-is-right

Here, ecj accepts the code, while javac rejects.

On closer look this is (probably) caused by a bug similar to javac's https://bugs.openjdk.java.net/browse/JDK-8026527 in that we accept

   ⟨AtomicReference#RAW <: AtomicReference<?>⟩

where in fact types are only convertible, no subtype relation.

Simply switching from isCompatibleWith() to isSubtypeOf() produces these differences wrt javac (9.0.1) in GRT_18:

testBug424415b: ecj accept, javac reject
testBug488663:  ecj reject, javac accept
testBug506022b: ecj reject, javac accept (with warnings)

The same experiment before the pending fix yields:

testBug424415b: ecj accept, javac reject
testBug488663:  ecj reject, javac accept
this bug:       ecj accept, javac reject

Disregarding the first two differences (which are independent of the issue discussed here) it seems we can choose between this bug and (part of) Bug 506022...
Comment 1 Eclipse Genie CLA 2017-12-19 13:41:53 EST
New Gerrit change created: https://git.eclipse.org/r/114442
Comment 2 Stephan Herrmann CLA 2017-12-19 16:17:22 EST
(In reply to Eclipse Genie from comment #1)
> New Gerrit change created: https://git.eclipse.org/r/114442

This "obvious fix" gave more regressions than expected (at 1.8 and 9):

org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest.test014h
org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest.test014i
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test0394
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test0459
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test0600
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test0901
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1234
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1235
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1349
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1429
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1430
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test277643
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test280054
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test283306
org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test294724
org.eclipse.jdt.core.tests.compiler.regression.GenericsRegressionTest.test283353
org.eclipse.jdt.core.tests.compiler.regression.GenericsRegressionTest.test434118
org.eclipse.jdt.core.tests.compiler.regression.MethodVerifyTest.test094
org.eclipse.jdt.core.tests.compiler.regression.NullTypeAnnotationTest.testTypeVariable18raw
org.eclipse.jdt.core.tests.compiler.regression.GenericsRegressionTest_1_8.testBug506022b
Comment 3 Stephan Herrmann CLA 2018-01-11 07:00:14 EST
To overlay the list of regressions with the current state in bug 404648:

(In reply to Stephan Herrmann from comment #2)
> (In reply to Eclipse Genie from comment #1)
> > New Gerrit change created: https://git.eclipse.org/r/114442
> 
> This "obvious fix" gave more regressions than expected (at 1.8 and 9):

Tests where current state (without pending patch) detects a difference between ecj & javac:

> org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test277643
> org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test283306

Of these, test277643 changed behavior between javac8 and javac9.

In all other tests mentioned in comment 2 current behavior (without pending patch) is in sync with javac.

Ergo: that patch does not bring us closer to javac, quite to the contrary.
Comment 5 Stephan Herrmann CLA 2018-01-11 12:17:42 EST
(In reply to Eclipse Genie from comment #4)
> Gerrit change https://git.eclipse.org/r/114442 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=ec76c89defa5f96571519ef98af5fe717abfdb09

I found a deficiency in our implementation of isSubTypeOf(), fixed & released for 4.8 M5.

NB: I introduced a new parameter simulatingBugJDK8026527, but clients are not yet consistent about when to pass false, or propagate their own simulatingBugJDK8026527 value. Since this is neither spec'ed nor influences the outcome of tests I can't really tell which strategy should be "correct".
Comment 6 Stephan Herrmann CLA 2018-01-14 07:23:30 EST
The latest test build[1] informed me, that the fix is not good: the test expects the wrong result thus creating a failure during comparison with javac.

Re-opening.


[1] https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-9/5/testReport/
Comment 7 Stephan Herrmann CLA 2018-01-18 11:28:14 EST
I'm having good mail exchange with Oracle regarding this issue.

Rejecting the example in this bug can be achieved by post-inference sanity checks, which would detect that an argument is not compatible to the corresponding method parameter.

Unfortunately, adding such sanity check breaks other tests, one of which is currently being discussed with Oracle.
Comment 8 Stephan Herrmann CLA 2018-01-18 18:41:16 EST
In discussing this with Oracle we touched on the issues of bug 448793: javac applies the branch in 18.4, where fresh type variables Y1,... are created, because the variables to be resolved appear in capture bounds. We don't get there because of prematurely deleting capture bounds during incorporate.

I made some more experiments with avoiding that premature deleting, but this causes around 30 regressions just in GRT_18.

I even tried the advice quoted in bug 448793 comment 3, to not much avail.

Also the recommended sanity checks cause many regressions.

For the records: the test we discussed was testBug506022b() where inference needs to infer a parameter to be a wildcard capture, but nowhere in JLS do I see a chance that inference could make use of the wildcard :(


=> Moving out of M5, not sure if this is a game we can win. Better let missing sanity checks camouflage the problems we have around the business of capture bounds and fresh type variables.
Comment 9 Stephan Herrmann CLA 2018-02-22 07:01:14 EST
After all discussion (internal and with Oracle) it is still not clear how exactly javac is handling wildcard capture during type inference, nor what we should be doing in this field. 
Until bug 448793 is resolved (if possible), I don't see how we can make progress in this bug.
Comment 10 Eclipse Genie CLA 2022-11-12 17:17:39 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.