Skip to content

Optional parameters in extension methods not working #692

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 19, 2025 · 2 comments
Open

Optional parameters in extension methods not working #692

EotT123 opened this issue Apr 19, 2025 · 2 comments

Comments

@EotT123
Copy link
Contributor

EotT123 commented Apr 19, 2025

It appears that optional and named parameters in extension methods aren't functioning correctly.

public class Foo {}

@Extension
public class FooExt {
    public static String test(@This Foo foo, String bar="", String foobar){
        return bar + foobar;
    }
}

new Foo().test("bar", "foobar"); // OK
new Foo().test(bar:"bar", foobar:"foobar"); // NOK when using using named parameters
new Foo().test(foobar:"foobar"); // NOK when only supplying required parameter
EotT123 pushed a commit to EotT123/manifold-test that referenced this issue Apr 19, 2025
EotT123 pushed a commit to EotT123/manifold-test that referenced this issue Apr 19, 2025
@EotT123
Copy link
Contributor Author

EotT123 commented Apr 25, 2025

I've fixed the example, I forgot to add a default value for one of the parameters.

The following warning is also displayed: Maybe missing '@This' to declare an instance extension method?". The first parameter is clearly annotated with @This, but while using the debugger, I noticed that the annotation isn't present in the generated code.

@EotT123
Copy link
Contributor Author

EotT123 commented May 18, 2025

The generated extension methods don't seem to be anotated with @This:

@Extension
public class FooExt {
    public static String test(@This Foo foo, String bar, String foobar) {
        return bar + foobar;
    }

    @manifold_params("foo,opt$bar,foobar")
    public static String $test(Foo foo, boolean $isBar, String bar, String foobar) {
        String var10001 = $isBar ? bar : "";
        String var10002 = $isBar ? bar : "";
        return test(foo, var10001, foobar);
    }

    @manifold_params("foo,bar,foobar")
    public static String test(Foo foo, String foobar) {
        return $test(foo, false, (String)null, foobar);
    }

    static {
        IBootstrap.dasBoot();
    }
}

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant