Skip to content

@new @variadic is not supported? #5363

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

Closed
cannorin opened this issue Mar 11, 2022 · 0 comments · Fixed by #5364
Closed

@new @variadic is not supported? #5363

cannorin opened this issue Mar 11, 2022 · 0 comments · Fixed by #5364

Comments

@cannorin
Copy link
Contributor

In JavaScript, constructors can also have a rest parameter, and thus can be variadic.

'use strict';
class Foo {
    constructor(...names) {
        this.names = names;
    }
}
let foo = new Foo("bar", "baz");
console.log(foo.names);

Currently, ReScript can't easily bind to these variadic constructors because @new @variadic is not supported:

type foo
@get external names: foo => array<string> = "names"
@new @variadic external makeFoo : array<string> => foo = "Foo"
// ^ Conflicting FFI attributes found: Attribute found that conflicts with %@new
let foo = makeFoo(["bar", "baz"])
Js.log(foo->names)

As there is no easy workaround to this (especially when the class is imported), I believe @new @variadic should be supported.

The relevant code is here: https://github.com/rescript-lang/rescript-compiler/blob/4419af7d822c7c9dffe21532624810985915908b/jscomp/frontend/ast_external_process.ml#L792-L811

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

Successfully merging a pull request may close this issue.

1 participant