buzz-language / buzz

👨‍🚀 buzz, A small/lightweight statically typed scripting language
https://buzz-lang.dev
MIT License
1.22k stars 34 forks source link

Misleading error underline and reporting #207

Closed hexaredecimal closed 11 months ago

hexaredecimal commented 11 months ago

Recently encountered such an error where I forgot to add a ',' after the name field but the compiler complains and highlights the wrong position where the error occurred. The error message is accurate in my opinion.

main.buzz:18:9: [E74] Syntax error: Expected `,` after field initialization.
    16 ╭─         name = "Vincent", 
    17 │          age = 21
    18 │          height = 5.5,  
       ┆          ╭─────
       ┆          ╰─ Expected `,` after field initialization.
    19 │      }; 
    20 ╰─     print("Hello, I'm {me.name} and I'm {me.age} years old"); 

Is this intentional? I think the underline should be at the end, on the line where the comma is missing, possibly underlining the value assigned to the field or maybe even underline the entire line.

    15 ╭─     Person me = Person {
    16 │          name = "Vincent" 
    17 │          age = 21,
       ┆          ╭──
       ┆          ╰─ Expected `,` after field initialization.
    18 │          height = 5.5,  
    19 ╰─     }; 

When I remove it on the first field the error get reported on the second field? why? The same thing happens when you are missing a ';'. The error message is still correct but the underline is out of place.

main.buzz:23:5: [E74] Syntax error: Expected `;` after expression.
    21 ╭─     me.age = me.growUp();
    22 │      me = Person{name = "Kelly"}
    23 │      print("Hello, I'm {me.name} and I'm {me.age} years old"); 
       ┆      ╭────
       ┆      ╰─ Expected `;` after expression.
    24 │  }
    25 ╰─ 
giann commented 11 months ago

The error gets reported on the unexpected token. Here the parser sees an identifier instead of a comma and reports it.