You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the features of the @as decorator in externals is it can inject and erase function arguments, filling them with a value. This leads to an interesting (but niche) side-effect, where using @as within an @obj decorator allows object properties to be erased and filled with a value. Or at least it used to; uncurried mode breaks this.
Change that to v11 and it prints a very strange error where more arguments are "required" than the type it prints:
This uncurried function has type
(
~read: (t, ~size: Js.nullable<int>) => unit,
~autoDestroy: bool=?,
unit,
) => configObj
It is applied with 2 arguments but it requires 4.
It seems that while @as does still inject the argument, in uncurried mode it fails to completely erase it. A further effect of this is to break optional argument handling (when this first happened I thought uncurried @obj no longer supported optional arguments).
Examples like this:
```
@obj
external makeOptions: (
~objectMode: @as(json`false`) _,
~name: string,
unit,
) => int = ""
```
change the arity of the function.
The arity of uncurried functions is determined at parsing type.
This means that this peculiarity of externals affects parsing.
This PR gives an approximate workaround based on the labelled arg having `@as`, and the type being `_` (the any type).
Fixes#6517
* Workaround for `@as`in labels in uncurried externals.
Examples like this:
```
@obj
external makeOptions: (
~objectMode: @as(json`false`) _,
~name: string,
unit,
) => int = ""
```
change the arity of the function.
The arity of uncurried functions is determined at parsing type.
This means that this peculiarity of externals affects parsing.
This PR gives an approximate workaround based on the labelled arg having `@as`, and the type being `_` (the any type).
Fixes#6517
* Example with 2 default args.
* Add example outside externals, which should not fail.
* Restrict workaround to only fire inside an external.
One of the features of the
@as
decorator in externals is it can inject and erase function arguments, filling them with a value. This leads to an interesting (but niche) side-effect, where using@as
within an@obj
decorator allows object properties to be erased and filled with a value. Or at least it used to; uncurried mode breaks this.One of the libraries I work on makes use of the technique, to model a NodeJS API that changes type based on a config option. The details are a bit complicated so I built a simplified playground example.
Change that to v11 and it prints a very strange error where more arguments are "required" than the type it prints:
It seems that while
@as
does still inject the argument, in uncurried mode it fails to completely erase it. A further effect of this is to break optional argument handling (when this first happened I thought uncurried@obj
no longer supported optional arguments).Further discussion on the forum
https://forum.rescript-lang.org/t/the-big-migration-thread-for-rescript-v11-and-uncurried-mode/4769/37?u=spyder
The text was updated successfully, but these errors were encountered: