Stream: beginners

Topic: ✔ "final expression in that series of definitions"


view this post on Zulip Jared Cone (Sep 24 2024 at 06:10):

I seem to run into this compile error often in various contexts. What does it mean?

I just finished parsing an expression with a series of definitions,

and this line is indented as if it's intended to be part of that
expression:

 1│  app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br" }
 2│
 3│  import pf.Stdin
 4│  import pf.Stdout
 5│  import pf.Tty
 6│  import pf.Sleep
 7│
 8│  main =
 9│      Stdout.line! "Hello, World!"
10│      Tty.enableRawMode {}
11│      Sleep.millis! 1000
12│      input = Stdin.bytes {}
         ^

However, I already saw the final expression in that series of
definitions

view this post on Zulip Oskar Hahn (Sep 24 2024 at 06:17):

I think the error is in line 10. You forgot the !.

That means, that roc thinks, that you want to return a Task in line 10, instead of "awaiting" it.

In other languages, it would look like this:

main = () => {
  await Stdout.line("Hello, World");
  return Tty.enableRawMode({});
  await Sleep.milis(1000)
  const input = Stdin.bytes({}); // you probably want to use await / ! , here as well
}

view this post on Zulip Jared Cone (Sep 24 2024 at 06:31):

thanks!

view this post on Zulip Anton (Sep 24 2024 at 08:03):

@Jared Cone how would you rephrase this error message to give the best tip to your past self?

view this post on Zulip Jared Cone (Sep 25 2024 at 05:54):

Maybe if the error was on line 10 (where I forgot the '!'), and the message was something like:

This expression is not an assignment, so the result of this expression becomes the return value of the function.
However there appears to be additional lines to the function after this final expression.
These additional lines will not be evaluated.

and if the final expression is a Task, throw in a "Did you forget to await the Task by using the '!' suffix?"

view this post on Zulip Anton (Sep 26 2024 at 18:22):

Thanks @Jared Cone, improving the line number and detecting a Task would take some time, so I tried to make some quick improvements by adding some tips to the error message, see PR#7120.

view this post on Zulip Notification Bot (Sep 28 2024 at 02:48):

Jared Cone has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC