Hello all,
I am dipping my toes with the new compiler and I hit something strange, not knowing if it's me not understanding something obvious with the new syntax or if I've hit a bug/unimplemented feature.
Context: I am using the latest basic_cli with the recommended nightly build of roc (although I get the same error with the latest, along with others).
I've identified the part I don't understand within the code which is in the walk_directory! method:
app [main!] { pf: platform "../roc-new-compiler/basic-cli/platform/main.roc"}
import pf.Stdout
import pf.Dir
main! = |args| {
root_paths = List.drop_first(args, 1).take_first(1)
dirs = fold!(root_paths, [], walk_directory!)
Stdout.line!(Str.inspect(dirs))
Ok({})
}
fold! : List(item), state, (state, item => state) => state
fold! = |list, init, step| {
var $state = init
for item in list {
$state = step($state, item)
}
$state
}
walk_directory! : List(Str), Str => List(Str)
walk_directory! = |paths, root_path| {
children = match Dir.list!(root_path) {
Ok(new_paths) => new_paths
Err(_) => []
}
end_state = fold!(children, {files: [], directories: []},
# This doesn't work:
#
# |state, _path|
# full_path = "A file name"
# {..state, files: List.append(state.files, full_path)}
# But this does works :
|state, _path|
{..state, files: List.append(state.files, "A file name")}
)
List.concat(paths, end_state.files)
}
With the chunk of code uncommented I get this error:
-- PARSE ERROR -----------------------------------
A parsing error occurred: expected_expr_apply_close_round
This is an unexpected parsing error. Please check your syntax.
┌─ main.roc:34:17
│
34 │ end_state = fold!(children, {files: [], directories: []},
│ ^^^^^
-- UNEXPECTED TOKEN IN EXPRESSION ----------------
The token ) is not expected in an expression.
Expressions can be identifiers, literals, function calls, or operators.
┌─ main.roc:45:9
│
45 │ )
│ ^
The issue with this is you are missing the block expression I think
# no block
|state, _path|
full_path = "A file name"
{..state, files: List.append(state.files, full_path)}
# with block
|state, _path| {
full_path = "A file name"
{..state, files: List.append(state.files, full_path)}
}
Claude Précourt has marked this topic as resolved.
Exactly! It felt like a simple mistake... Thank you so much!
I feel like we had a rough plan for detecting this exact syntax error and providing a more helpful error message... but I can't remember.
I imagine it is difficult to solve in a really general way, so I feel like it was a heuristic trial and error thing
@Joshua Warner can you remember if we had a plan for this?
Roughly: track indentation and use that as a hint in the parser, but only for error code paths (never the happy path)
I also have a pet project idea to train a tiny languages model of like 20m parameters that knows how to fix a variety of syntax errors, is well within the range that can be cheaply inferenced locally, and can just ship with the compiler.
Generally bullish on the approach of having a significant corpus of roc code, with a way to introduce real syntax errors in ways that the fix remains “obvious” by looking at a small amount of context. Then you use that to either train a model, or tune a bunch of heuristics (possibly automatically), etc.
Would it be worth putting anything together about this in a GH Issue so we can track it -- even if it's only an R&D concept at this stage?
It sounds like a generally interesting problem someone may want to pick up -- if you haven't already called dibbs @Joshua Warner
It’s wide open! Happy to mentor someone a bit, but my time is incredibly limited currently.
Last updated: Feb 20 2026 at 12:27 UTC