Skip to content

Bad error message on non-unit return value in block with structuring bind. #5217

@ChrisPenner

Description

@ChrisPenner

Normally if you have a line that returns something other than () in a block you get a nice warning about it, e.g.

test = 
  1
  2
  I found a value  of type:  Nat
  where I expected to find:  Unit

     14 |   1
     15 |   2

    from right here:

     14 |   1

  Hint: Actions within a block must have type Unit.
        Use _ = <expr> to ignore a result.

However, if there's a destructuring bind in the block, the error message mentions a match/with when there isn't one:

type UserId = UserId Nat

testTerm = do
  (UserId x) = UserId 88
  "testing"
  printLine "hello"
  printLine "hi"
  x
  Each case of a match / with expression need to have the same type.

  Here, one   is:  Unit
  and another is:  Text


      6 |   "testing"
      7 |   printLine "hello"
      8 |   printLine "hi"
      9 |   x

    from these spots, respectively:

      6 |   "testing"

Also, all of the block is treated as part of the error (lines 6-9) when really the error is just line 6, so the LSP erroneously highlights the entire block.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions