rescript-compiler
rescript-compiler copied to clipboard
Record type spreads in inline records does not work if there's only a spread
type x = {name: string}
type y = Person({...x})
Gives:
I'm not sure what to parse here when looking at ")".
Add a field before and it parses fine:
type x = {name: string}
type y = Person({age: int, ...x})
Add a field after and it tries to parse the spread as an object:
type x = {name: string}
type y = Person({...x, age: int})
A record type declaration doesn't support the ... spread. Only an object (with quoted field names) does.
So, this is ambiguous with regular object spreads. But previously we've changed things up to prefer records now that records are so much more powerful, and there are less reasons to use regular objects. So it'd be safe to parse this as a record spread instead of an object spread, in my opinion.
Or even if we don't support this, a better error seems essential. In both spread-only and spread-first cases.