Open bugarela opened 2 months ago
Workaround: use List(bar)
instead of [bar]
I stumbled upon a similar issue while writing typescript and the autoformatter immediately made me understand I wrote something different then what I expected. I wrote
const a = foo(x)
[a, bar]
(forgetting the return
keyword in the last line). As soon as I saved the file, it got formatted into
const a = foo(x)[a, bar]
which made me realize something was wrong.
A similar issue was reported by @angbrav involving tuple constructors and operator calls. In this example, one tuple construction ((bar, 1)
) is parsed as the parameters in a operator call, and later, one operator call (head()
) is parsed as a field access + empty tuple construction. So they "cancel each other out" and form a valid module.
module test {
pure def foo(x) =
pure val bar = x
(bar, 1)
pure def foo2(x) =
pure val baz = x.head()
x
}
is parsed as
module test {
pure def foo(x) =
pure val bar = x(bar, 1)
pure def foo2(x) =
pure val baz = x.head { Tup() }
x
}
Wrapping the first top-level def in curly braces fixes the problem:
module test {
pure def foo(x) = {
pure val bar = x
(bar, 1)
}
pure def foo2(x) =
pure val baz = x.head()
x
}
I just stumbled upon a similar issue as @angbrav . I cannot create a minimal example (because I do not udnerstand what exactly is happening) so let me describe how/when the problem occurs.
val
, all is goodval
s, a parsing error is reported that an existing function does not exist.Is it an instance of the same error? To the best of my understanding, any number of helper val
s before a single expression should be legal syntax
Using
[]
like this:causes a completely unrelated error about cyclic definitions:
because this is (wrongfully) parsed as: