Skip to content

Repeated patterns in the same line don't have the correct column highlight #1565

Open
@cg-jl

Description

The column highlight for the "repeated patterns" error points incorrectly to the first pattern in the line, which
causes confusion:


fn main() {
   match 1u8 {
      b'a' | b'b' | b'b' => {}
      else => {}
   }
}

This produces the repeated patterns error, but both highlights (error and hint) are on b'a', which is not the repeated. The repeated pattern is b'b'.

Bad error message:

Error: Duplicated match pattern
────┬─ boog.jakt:4:10
 26 │     match 1u8 {
 27 │         b'a' | b'b' | b'b' => {}
    │          ──┬
    │            ╰─ Duplicated match pattern
 28 │         else => {}
────┴─
Hint: Original pattern here
────┬─ boog.jakt:4:10
 26 │     match 1u8 {
 27 │         b'a' | b'b' | b'b' => {}
    │          ──┬
    │            ╰─ Original pattern here
 28 │         else => {}
────┴─

Expected error message:

 Error: Duplicated match pattern
 ───┬─ boog.jakt:4:23    | <- notice how the column number changes here. This should be the only thing to test, really.
  3 │     match 1u8 {
  4 │         b'a' | b'b' | b'b' => {}                     
    │                       ──┬                            | notice how the offset in of the highlight is different, since it was moved
    │                         ╰─ Duplicated match pattern  | 
  5 │     }
 ───┴─
 Hint: Original pattern here
 ───┬─ boog.jakt:4:10
  3 │     match 1u8 {
  4 │         b'a' | b'b' | b'b' => {}                    
    │                ──┬                                  | I've also had to move the highlight here
    │                  ╰─ Original pattern here
  5 │     }
 ───┴─

Note that Jakttest currently doesn't support error message locations, only searching through their titles, so automating this test is not going to be pretty (if it is done) for the moment.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions