── MISSING FINAL EXPRESSION ───────────────────────────────────────── main.roc ─
I am partway through parsing a definition, but I got stuck here:
53│ subItemWalker =
54│ List.walk subsItems {invalidEncounters: Bool} \walkerState, walkerItem ->
55│ if walkerState.invalidEncounters == Bool.true then
56│ {invalidEncounters: Bool.true}
57│ else
58│ itemSplit = Str.split walkerItem " "
59│ countStrRaw = List.get itemSplit 0
60│ countStr =
61│ when countStrRaw is
62│ Ok val -> val
63│ Err OutOfBounds -> crash "Nope, doesn't work"
64│ count =
65│ when Str.toU32 countStr is
66│ Ok val -> val
67│ Err InvalidNumStr -> crash "Nope, doesn't work"
68│ # at this point, we got the count of cubes for this specific color.
69│ colorStrRaw = List.get itemSplit 1
70│ colorStr =
71│ when colorStrRaw is
72│ Ok val -> val
73│ Err OutOfBounds -> crash "Nope, doesn't work"
74│ # we also got the color name.
75│ when colorStr is
76│ "red" ->
77│ if count > 12 then
78│ { invalidEncounters: Bool.true }
79│ else
80│ { invalidEncounters: Bool.false }
81│ "green" ->
82│ if count > 13 then
83│ { invalidEncounters: Bool.true }
84│ else
85│ { invalidEncounters: Bool.false }
86│ "blue" ->
87│ if count > 14 then
88│ { invalidEncounters: Bool.true }
89│ else
90│ { invalidEncounters: Bool.false }
91│ _ -> { invalidEncounters: Bool.false }
^
This definition is missing a final expression. A nested definition
must be followed by either another definition, or an expression
x = 4
y = 2
x + y
The error means that roc is expecting some sort of value, but instead things are just stored in variables. As a small example:
invalid:
main : U32
main =
x = 7
y = 3
out = x + y
valid:
main : U32
main =
x = 7
y = 3
x + y
I've tried using the value returned from subItemWalker
as return value, but I still get the same error.
── MISSING FINAL EXPRESSION ───────────────────────────────────────── main.roc ─
I am partway through parsing a definition, but I got stuck here:
92│ subItemWalker
^
This definition is missing a final expression. A nested definition
must be followed by either another definition, or an expression
So just looked at it, and at least from just that snippet of code, it seems there is an issue that may be partially confusing the compiler. That said, this issue may still be real based on context around this code.
Anyway, the bug is that in the List.walk
line it is just written Bool
instead of Bool.false
. After changing that is the error fixed?
Otherwise, we may need more context of the surrounding scope to debug this.
Unfortunately that did not fix it, where can I share my entire code? I was solving AoC :p
Looks like you now have exactly the same problem at the next scope outwards
When define a thing like subWalker =
or subsetExplorer =
, you actually need to use it afterwards.
If the code defines a bunch of things and then doesn't use them, this error can happen.
I actually don't have much experience with Roc in general, I thought, "hey, this language looks nice, might do some advent of code in it", and here I am, 4 hours later.
Changing the last two lines to:
subItemWalker.invalidEncounters
subsetExplorer
Then updating the other List.walk line to Bool.false
instead of just Bool
looks to work.
Brendan Hansknecht said:
Changing the last two lines to:
subItemWalker.invalidEncounters subsetExplorer
Then updating the other List.walk line to
Bool.false
instead of justBool
looks to work.
Do you mean changing
_ -> { invalidEncounters: Bool.false }
subItemWalker
to that?
oh, sorry, still leave in the _ -> { invalidEncounters: Bool.false }
So just replacing subItemWalker
with that
gotchu
okay, those errors seem to be gone now :exploding_head:
I guess we may need to improve that error message to help explain the issue better. Clearly the example didn't help here. Also the amount of code selected for the error may be too small in some cases.
I made #6156 for improvements to this error message
Last updated: Jul 06 2025 at 12:14 UTC