Bug 540846 - [regression] Cannot infer type argument(s) for <R> map(Function<? super T,? extends R>
Summary: [regression] Cannot infer type argument(s) for <R> map(Function<? super T,? e...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.9   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.11 M3   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2018-11-06 11:20 EST by Paul Crockett CLA
Modified: 2019-02-21 02:32 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Crockett CLA 2018-11-06 11:20:06 EST
The following is compiled ok by Eclipse 4.8.0 and Oracle JDK 1.8, but fails to compile in Eclipse 4.9.0:

    private List<Object> getRowValues(Map<String, BigDecimal> record, Stream<String> factors) {
        return Stream.concat(
            factors.map(f -> {
                if (f.equals("x")) {
                    return record.get(f);
                } else {
                    return "NM";
                }
            }),
            Stream.of(BigDecimal.ONE)
        )
        .map(v -> (v instanceof BigDecimal) ? ((BigDecimal) v).setScale(10, BigDecimal.ROUND_HALF_UP) : v)
        .collect(Collectors.toList());
    }

Error: Cannot infer type argument(s) for <R> map(Function<? super T,? extends R>

The error goes away by either commenting out the second .map call, or by changing either of .map to .<Object>map(...)
Comment 1 Stephan Herrmann CLA 2018-11-08 05:44:24 EST
Accepted by ecj 4.8, rejected since 4.9 M2, which makes bug 537089 a likely candidate to have broken it. Seeing the ternary in the mix, it is indeed likely that some change relating to intersection types has a finger in the pie.

Tentatively putting this on the radar, time permitting.
Comment 2 Eclipse Genie CLA 2019-02-05 16:32:14 EST
New Gerrit change created: https://git.eclipse.org/r/136331
Comment 3 Stephan Herrmann CLA 2019-02-05 16:37:51 EST
(In reply to Eclipse Genie from comment #2)
> New Gerrit change created: https://git.eclipse.org/r/136331

Yep, an issue of intersection types, indeed. We had intersection types on both sides of the equation, requiring us to resolve a constraint of the shape

 Object & Serializable & Comparable<?> <: Object & Serializable & Comparable<?>

Method ITB18.isSubtypeOf() wasn't yet up to the task. I borrowed and adjusted code from its isCompatibleWith() and all looks fine for this case.
Comment 5 Stephan Herrmann CLA 2019-02-06 20:03:50 EST
(In reply to Eclipse Genie from comment #4)
> Gerrit change https://git.eclipse.org/r/136331 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=bcec7451e941decddf86ddcdbe87a1f9b59eec30

In addition to what's said in comment 3 I had to cope with an unrelated(?) failure in ModuleBuilderTests.testBug520147b. Made the test more explicit (about accepting a compile error on the intermediate project p2) and fixed the failure in ModuleDeclaration.analyseModuleGraph() (when checking exported packages, we don't want SplitPackageBindings).

Released for 4.11 M3
Comment 6 Manoj N Palat CLA 2019-02-21 02:32:24 EST
Verified for Eclipse 4.11 M3 with Build id: I20190218-1800