Stream: beginners

Topic: Not sure what this means, what exactly is wrong?


view this post on Zulip [REDACTED] (Dec 02 2023 at 17:22):

── 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

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 17:26):

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

view this post on Zulip [REDACTED] (Dec 02 2023 at 17:28):

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

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 17:31):

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?

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 17:31):

Otherwise, we may need more context of the surrounding scope to debug this.

view this post on Zulip [REDACTED] (Dec 02 2023 at 17:33):

Unfortunately that did not fix it, where can I share my entire code? I was solving AoC :p

view this post on Zulip [REDACTED] (Dec 02 2023 at 17:35):

https://pastebin.com/YRNjrqpH

view this post on Zulip Brian Carroll (Dec 02 2023 at 17:37):

Looks like you now have exactly the same problem at the next scope outwards

view this post on Zulip Brian Carroll (Dec 02 2023 at 17:38):

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.

view this post on Zulip [REDACTED] (Dec 02 2023 at 17:39):

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.

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 17:39):

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.

view this post on Zulip [REDACTED] (Dec 02 2023 at 17:41):

Brendan Hansknecht said:

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.

Do you mean changing

                                _ -> { invalidEncounters: Bool.false }
                subItemWalker

to that?

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 17:42):

oh, sorry, still leave in the _ -> { invalidEncounters: Bool.false }

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 17:42):

So just replacing subItemWalker with that

view this post on Zulip [REDACTED] (Dec 02 2023 at 17:42):

gotchu

view this post on Zulip [REDACTED] (Dec 02 2023 at 17:45):

okay, those errors seem to be gone now :exploding_head:

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 17:46):

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.

view this post on Zulip Anton (Dec 02 2023 at 18:50):

I made #6156 for improvements to this error message


Last updated: Jul 06 2025 at 12:14 UTC