Stream: beginners

Topic: Recover from error inside string interpolation not allowed?


view this post on Zulip Kevin Hovsäter (Feb 22 2025 at 16:15):

I tried doing the following in Roc:

"Hello ${Err("No name provided") ?? "Jane"}!"

Which produces the following error message:

── SYNTAX PROBLEM ──────────────────────────────────────────────────────────────

This string interpolation is invalid:

4│      "Hello ${Err("No name provided") ?? "Jane"}!"
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

String interpolations cannot contain newlines or other interpolations.

You can learn more about string interpolation at
<https://www.roc-lang.org/tutorial#string-interpolation>

This seems odd as there's no newlines and/or other interpolations. The tutorial also states that I'm allowed to put entire single-line expressions inside ${}. Have I hit a limitation of the compiler here?

view this post on Zulip Brendan Hansknecht (Feb 22 2025 at 17:59):

Interesting

view this post on Zulip Brendan Hansknecht (Feb 22 2025 at 18:00):

I guess this is for to how?? desugars

view this post on Zulip Brendan Hansknecht (Feb 22 2025 at 18:00):

It becomes a when ... is

view this post on Zulip Kevin Hovsäter (Feb 22 2025 at 18:07):

Ah, of course! I forgot that it's sugar just like the postfix ? is sugar for Str.concat...

Still somewhat surprising since it looks like a single-line expression.

view this post on Zulip Joshua Warner (Feb 22 2025 at 18:07):

I think that _ought_ to work, but just doesn't because bugs

view this post on Zulip Kevin Hovsäter (Feb 22 2025 at 18:15):

Worth reporting or will the new compiler most likely solve it?

view this post on Zulip Brendan Hansknecht (Feb 23 2025 at 03:35):

Joshua Warner said:

I think that _ought_ to work, but just doesn't because bugs

Yeah, totally agree

view this post on Zulip Brendan Hansknecht (Feb 23 2025 at 03:36):

Kevin Hovsäter said:

Worth reporting or will the new compiler most likely solve it?

Hopefully the new compiler will just fix this, but no guarantees. Might be worth just filing as a reminder.


Last updated: Jul 05 2025 at 12:14 UTC