gleam
gleam copied to clipboard
Compiler: At least one form of `use` misses a semicolon when compiled to JS
This Gleam
fn b() {
{
use a <- fn(cb) { cb(1) }
a
}
{
use b <- fn(cb) { cb(2) }
b
}
3
}
Produces this JavaScript with Gleam v1.0.0
function b() {
((cb) => { return cb(1); })((a) => { return a; })
((cb) => { return cb(2); })((b) => { return b; })
return 3;
}
Causing this error
((cb) => { return cb(2); })((b) => { return b; })
^
TypeError: (intermediate value)(...) is not a function
Due to a missing semicolon.
Thank you
FWIW as far as I could tell this actually is not specific to use
but rather to any block that returns a function
fn b() {
{
fn(cb) { cb(1) }
}
{
fn(cb) { cb(2) }
}
3
}
This also fails with TypeError: cb is not a function
because it compiles to
function b() {
((cb) => { return cb(1); })
((cb) => { return cb(2); })
return 3;
}
Ultimate root cause being that blocks cause the function definition to be parenthesized and thus callable