Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 342267

Summary: [1.5] Type mismatch: cannot convert from Maybe<capture#2-of ? extends U> to Maybe<U>
Product: [Eclipse Project] JDT Reporter: Michal Svoboda <svobomic>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, mat.gessel+eclipse, Olivier_Thomann, stephan.herrmann
Version: 3.7   
Target Milestone: 4.14 M3   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Michal Svoboda CLA 2011-04-08 07:29:07 EDT
Build Identifier: 3.7 M5

I got the following piece of code, that compiles with javac, but in eclipse IDE it shows the error message "Type mismatch: cannot convert from Maybe<capture#2-of ? extends U> to Maybe<U>" at the marked line.


public abstract class Maybe<T> {

    public static <T> Maybe<T> definitely(final T theValue) {
        return new DefiniteValue<T>(theValue);
    }

    public abstract <U> Maybe<U> to(Function<? super T, ? extends U> mapping);

    private static class DefiniteValue<T> extends Maybe<T> {

        private final T theValue;

        public DefiniteValue(T theValue) {
            this.theValue = theValue;
        }

        @Override
        public <U> Maybe<U> to(Function<? super T, ? extends U> mapping) {
            return definitely(mapping.apply(theValue));  // ERROR!
        }

    }

    public static interface Function<F, T> {

        T apply(F input);

    }

}


Reproducible: Always
Comment 1 Michal Svoboda CLA 2011-04-09 07:14:37 EDT
Simplified (somewhat) case:

import java.util.Collections;
import java.util.List;

public class Generics {

	public List<Generics> something(List<? extends Generics> c) {
		return Collections.singletonList(c.get(0));
	}
	
}

The code is equivalent to the following one (local variable introduced), which causes no error in eclipse.

	public List<Generics> something(List<? extends Generics> c) {
		Generics o = c.get(0);
		return Collections.singletonList(o);
	}


Version from Help:
Version: Helios Service Release 2
Build id: 20110218-0911
Comment 2 Stephan Herrmann CLA 2014-11-02 08:24:55 EST
Problem still exists at 1.7, but at 1.8 ecj compiles this just fine.
Comment 3 Mat Gessel CLA 2019-10-29 17:40:11 EDT
Both code examples work for me in JDT 3.18.100.v20190916-1045
Comment 4 Stephan Herrmann CLA 2019-10-29 17:47:24 EDT
(In reply to Mat Gessel from comment #3)
> Both code examples work for me in JDT 3.18.100.v20190916-1045

thanks for retesting.

Let's be honest:
- at compliance 1.7- ecj still reports an error, but not at 1.8 and greater
- we don't have plans to fix this kind of 1.7-only problem, we can't even be
  sure the spec of that version positively covers this case.
Comment 5 Jay Arthanareeswaran CLA 2019-11-21 04:51:08 EST
Verified for 4.14 M3 using build I20191119-1250