Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve multiline errors #77

Closed
brendanzab opened this issue Jun 6, 2019 · 9 comments
Closed

Improve multiline errors #77

brendanzab opened this issue Jun 6, 2019 · 9 comments

Comments

@brendanzab
Copy link
Owner

brendanzab commented Jun 6, 2019

As can be seen in the emitter example the error for multiline errors could be improved.

Currently we render:

   ┌── FizzBuzz.fun:4:13 ───
   │
 4 │ fizz₁ num = case (mod num 5) (mod num 3) of
 5 │     0 0 => "FizzBuzz"
 6 │     0 _ => "Fizz"
 7 │     _ 0 => "Buzz"
 8 │     _ _ => num
   │             -------------- `case` clauses have incompatible types
   │

Instead, it might be nice if we followed rustc's lead, and tried to mark around the region instead:

   ┌── FizzBuzz.fun:4:13 ───
   │
 4 │   fizz₁ num = case (mod num 5) (mod num 3) of
   │ ╭─────────────╯
 5 │ │     0 0 => "FizzBuzz"
 6 │ │     0 _ => "Fizz"
 7 │ │     _ 0 => "Buzz"
 8 │ │     _ _ => num
   │ ╰──────────────╯ `case` clauses have incompatible types
   │

Eventually we could try to combine errors like so:

error[E0308]: `case` clauses have incompatible types

   ┌── FizzBuzz.fun:8:12 ───
   │
 3 │   fizz₁ : Nat → String
   │                 ------ expected type `String` found here
 4 │   fizz₁ num = case (mod num 5) (mod num 3) of
   │ ╭─────────────╯
 5 │ │     0 0 => "FizzBuzz"
 6 │ │     0 _ => "Fizz"
 7 │ │     _ 0 => "Buzz"
 8 │ │     _ _ => num
   │ │            ^^^ expected `String`, found `Nat`
   │ ╰──────────────╯ `case` clauses have incompatible types
   │
   = expected type `String`
        found type `Nat`
@brendanzab
Copy link
Owner Author

Rustc tends to handle overlapping multiline errors cleverly too:

Screen Shot 2019-06-04 at 2 14 32 pm

@brendanzab
Copy link
Owner Author

@brendanzab
Copy link
Owner Author

Here's another idea for primary spans:

   ┌── FizzBuzz.fun:4:13 ───
   │
 4 │   fizz₁ num = case (mod num 5) (mod num 3) of
   │ ╭─────────────^
 5 │ │     0 0 => "FizzBuzz"
 6 │ │     0 _ => "Fizz"
 7 │ │     _ 0 => "Buzz"
 8 │ │     _ _ => num
   │ ╰──────────────^ `case` clauses have incompatible types
   │

Not sure how to do secondary spans. This looks kinda weird:

   ┌── FizzBuzz.fun:4:13 ───
   │
 4 │   fizz₁ num = case (mod num 5) (mod num 3) of
   │ ╭─────────────-
 5 │ │     0 0 => "FizzBuzz"
 6 │ │     0 _ => "Fizz"
 7 │ │     _ 0 => "Buzz"
 8 │ │     _ _ => num
   │ ╰──────────────- `case` clauses have incompatible types
   │

@brendanzab brendanzab changed the title Improve multiline errors Implement snakey underlines! Jun 23, 2019
@brendanzab brendanzab changed the title Implement snakey underlines! Improve multiline errors Jun 23, 2019
@brendanzab
Copy link
Owner Author

I've decided to go with #77 (comment) in #98, but secondary spans still look kinda weird. Would appreciate some thoughts on alternatives!

@brendanzab
Copy link
Owner Author

brendanzab commented Jun 23, 2019

Here are some options for secondary labels that I posted on #98 (comment):

  1. single: - multi:
    foo <$> bar
    --- ^^^ --- a label about `bar`
    
      fizz₁ num = case (mod num 5) (mod num 3) of
    ╭─────────────┘
    
  2. single: - multi:
    foo <$> bar
    --- ^^^ --- a label about `bar`
    
      fizz₁ num = case (mod num 5) (mod num 3) of
    ╭─────────────╯
    
  3. single: multi:
    foo <$> bar
    ‾‾‾ ^^^ ‾‾‾ a label about `bar`
    
      fizz₁ num = case (mod num 5) (mod num 3) of
    ╭─────────────‾
    
  4. single: ' multi: '
    foo <$> bar
    ''' ^^^ ''' a label about `bar`
    
      fizz₁ num = case (mod num 5) (mod num 3) of
    ╭─────────────'
    
  5. single: " multi: "
    foo <$> bar
    """ ^^^ """ a label about `bar`
    
      fizz₁ num = case (mod num 5) (mod num 3) of
    ╭─────────────"
    
  6. single: - multi: '
    foo <$> bar
    --- ^^^ --- a label about `bar`
    
      fizz₁ num = case (mod num 5) (mod num 3) of
    ╭─────────────'
    

@brendanzab
Copy link
Owner Author

I actually think I'm leaning towards the last one!

@lpil
Copy link
Contributor

lpil commented Jun 23, 2019

I like 1 and 6 :)

@brendanzab
Copy link
Owner Author

Yeah, I went with 6 in 46cf125 - willing to be swayed towards 1 however.

@brendanzab
Copy link
Owner Author

Closing this in favor of #100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants