Bug 499955 - Diamond operator causes conversions to nest interfaces incorrectly
Summary: Diamond operator causes conversions to nest interfaces incorrectly
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on: 448793
Blocks:
  Show dependency tree
 
Reported: 2016-08-18 21:04 EDT by Cheng-Yu Pai CLA
Modified: 2022-06-04 14:05 EDT (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 Cheng-Yu Pai CLA 2016-08-18 21:04:28 EDT
There's a regression regarding Diamond operators, lambdas, and interfaces.

The following java code does not compile in Eclipse Neon (4.6) but compiles and rusn perfectly in Luna (4.4.2) and javac:

import java.util.function.Function;

public class Test {

	public static void main(String[] args) {
		foo(new Data(), new FunctionContainerImpl<>(a -> "test"));
	}

	public static <A extends Data> void foo(A data, FunctionContainer<A> container) {
		System.out.println(container.get(data, data));
	}

	interface FunctionContainer<A extends Data> {
		boolean get(A a, A b);
	}

	public static class Data {
	}

	public static class FunctionContainerImpl<A extends Data, T extends Comparable<T>>
			implements FunctionContainer<A> {

		private Function<A, T> getComparable;

		public FunctionContainerImpl(Function<A, T> getComparable) {
			this.getComparable = getComparable;
		}

		@Override
		public boolean get(A a, A b) {
			return getComparable.apply(a).compareTo(getComparable.apply(b)) == 0;
		}
	}
}


Error in eclipse says:
Type mismatch: cannot convert from String to Comparable<Comparable<T>>

It should be Comparable<T>, not Comparable<Comparable<T>>.
Comment 1 Jay Arthanareeswaran CLA 2016-11-18 03:05:26 EST
As of 4.7 M3 this is no longer an issue. Please try with a newer build.

Now I will try and find out which commit fixed this.
Comment 2 Eclipse Genie CLA 2019-03-28 01:38:07 EDT
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.
Comment 3 Stephan Herrmann CLA 2019-04-02 14:48:23 EDT
(In reply to Jay Arthanareeswaran from comment #1)
> As of 4.7 M3 this is no longer an issue. Please try with a newer build.

Sorry, but no: ecj rejects all the through today's HEAD.

The problem results from our optimization in bug 448794, which conflicts with the code controlled by SHOULD_WORKAROUND_BUG_JDK_8153748: we where caching a result even when inner inference was not yet ready.
Comment 4 Eclipse Genie CLA 2019-04-02 17:21:13 EDT
New Gerrit change created: https://git.eclipse.org/r/139933
Comment 5 Stephan Herrmann CLA 2019-04-02 17:26:00 EDT
(In reply to Eclipse Genie from comment #4)
> New Gerrit change created: https://git.eclipse.org/r/139933

WIP

The current issue can indeed be resolved by avoiding calls to registerResult() when inner is not ready. Unfortunately, this causes 13 failures in GRT_18 alone. 

Of those I started to debug test499351_extra2(), and observed that now invocation type inference for Collectors.toMap() *fails*. Need to dig deeper, to find out why.
Comment 6 Stephan Herrmann CLA 2019-05-18 16:34:52 EDT
Further into the rabbit whole, analyzing the failure in test499351_extra2() caused by the WIP change:

- calling infCtx18.forwardResults() is necessary to replace inner PolyPGMB with a regular PGMB, which avoids inner inference during resolvePolyExpressionArguments()

- if, OTOH, inner inference is triggered, it fails during incorporation of capture bounds, in this rule of 18.3.2:

  "If Ai is a wildcard of the form ?:
   - αi = R implies the bound false"

- one of the relevant bounds is created in IC18, in the branch that should never be entered due to "if (!tmpBoundSet.hasCaptureBound(variableSet))", which is without effect since bug 448793

=> It seems, that forwardResults() just prevents an inference that otherwise would fail for reasons that appear be beyond our powers. Keeping this current bug seems to be the lesser evil.

Will drop a few more details into bug 448793 and then stop investigating.
Comment 7 Eclipse Genie CLA 2022-06-04 14:05:56 EDT
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.