Skip to content

Optional parameters: Inline lambdas and method references not working for named arguments #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
EotT123 opened this issue Apr 16, 2025 · 2 comments

Comments

@EotT123
Copy link
Contributor

EotT123 commented Apr 16, 2025

When using named arguments with inline lambdas or method references, a compilation error occurs. However, the same code works when using unnamed arguments or assigning the lambda or method reference to a variable.​

Consider the following example class:

public class Foo {
    private final Function<String, Integer> fooFunction;
    private final boolean bar;

    public Foo(Function<String, Integer> fooFunction, boolean bar = false){
        this.fooFunction = fooFunction;
        this.bar = bar;
    }
}

Fails with a compilation error (Method reference expression is not expected here)

Attempt to instantiate the class using named arguments with an inline lambda or method reference results in the following error: Method reference expression is not expected here

new Foo(fooFunction: String::length);
new Foo(fooFunction: s -> s.length()); 

Works as expected

Instantiating the class using 'unnamed' arguments or assigning the lambda or method reference to a variable works fine.

new Foo(String::length);
new Foo(s -> s.length());

Function<String, Integer> fooFunction = String::length;
new Foo(fooFunction:fooFunction);
EotT123 pushed a commit to EotT123/manifold-test that referenced this issue Apr 16, 2025
@rsmckinney
Copy link
Member

This looks specific to the IJ plugin--it compiles okay on my end.

@EotT123
Copy link
Contributor Author

EotT123 commented Apr 18, 2025

Ah, you are right, no problems when compiling. Do you think it is (easily) fixable in the IJ plugin?

I was using the old '2024' IJ plugin, but now, since I've update the the latest IJ (2025.1), I'm also using the '2025' version of the plugin, but that doesn't make any difference.

EotT123 pushed a commit to EotT123/manifold-test that referenced this issue May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants