rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

[bug] @as can create type problems

Open tx46 opened this issue 2 months ago • 2 comments

this is a really stupid example that would likely never happen in real-life (but hey, you give a million monkeys infinite amount of time with keyboards...). if it DOES happen, it'll cost some developer x amount of hours to debug. it's kinda far out there, but not as far as @as("RE_EXN_ID)"...

right now i'm just having fun trying to break things to find bugs and i stumbled upon this.

exception Foo({@as("Error") e: string})
let s: string = try throw(Foo({e: "foo"})) catch {
| Foo({e}) => e
}
Console.log(s == "foo")
Console.log(s)

as you can imagine, this logs false and then an error object. i'm not sure what the takeaway is here.. possibly:

a) call me an idiot and close this b) come up with some way to prohibit use of or warn on using @as("Error") for inlined exception records (yeah, kinda niche...)

tx46 avatar Oct 13 '25 06:10 tx46

We recently did a similar fix for regular variants, where @tag + inline record field name overlap was prevented. Niche, but the same type of guard rails could be added here.

zth avatar Oct 13 '25 06:10 zth

Great finds btw, keep them coming @tx46 ! 😄

zth avatar Oct 13 '25 06:10 zth