gleam-lang/gleam

Add better error message when pattern matching on string prefix and suffix

Closed

#5,695 opened on May 9, 2026

 (2 comments) (0 reactions) (0 assignees)Rust (960 forks)batch import
good first issuehelp wanted

Repository metrics

Stars
 (21,417 stars)
PR merge metrics
 (Avg merge 10d 19h) (69 merged PRs in 30d)

Description

When attempting to pattern match on both the suffix and prefix of a string, the error message could be friendlier.

For example, with

case "my string!" {
  "my " <> object <> "!" -> todo
  start <> "!" -> todo
}

The current error is:

error: Syntax error
  ┌─ /private/tmp/match_string_end/src/match_string_end.gleam:5:21
  │
5 │     "my " <> object <> "!" -> todo
  │                     ^^ I was not expecting this

Found `<>`, expected one of:
- `->`

Hint: Did you mean to wrap a multi line clause in curly braces?

Compare to the error if you don't try to match on the string's prefix:

error: Syntax error
  ┌─ /private/tmp/match_string_end/src/match_string_end.gleam:6:5
  │
6 │     start <> "!" -> todo
  │     ^^^^^ This must be a string literal

We can't tell what size this prefix should be so we don't know
how to handle this pattern.

If you want to match one character consider using `pop_grapheme`
from the stdlib's `gleam/string` module.

Thanks to @the_tank_man_ from the discord for suggesting this :]

Also, I can start working on this.

Contributor guide