Skip to content

[Ternary operator] Inference failure involving standalone conditional expression argument #3775

Description

@lukeu

I have upgraded to Eclipse 4.35RC2 (jumping from 4.33) and I am now seeing a false compile error. The title is my best guess at the scenario in which this happens.

Minimal reproducer:

import java.util.Optional;

public class Snippet {
    public static void main(String[] args) {
        var d = ("a" == null ? null : 2.0);
        Optional.ofNullable("a" == null ? null : 2.0);
    }
}

As expected: var d is correctly inferred to be type Double

Unexpected: the same expression on the 2nd line yields this error:

"The method ofNullable(T) in the type Optional is not applicable for the arguments (Double)"

Metadata

Metadata

Labels

bugSomething isn't workingcompilerEclipse Java Compiler (ecj) related issuesregressionSomething was broken by a previous change

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions