unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.77k stars 268 forks source link

rough error message when `let` ends in a binding #1240

Open aryairani opened 4 years ago

aryairani commented 4 years ago
List.find : a -> [a] -> Optional Nat
List.find a as = todo ""

Map.delete : a -> Map a b -> Map a b
Map.delete a m = match m with
  Map ks vs ->
    match find a ks with
      None -> m
      Some i ->
        leftKs = take i ks
        leftVs = take i vs
        rightKs = drop (i+1) ks
        rightVs = drop (i+1) vs
  I'm not sure what _1450009 means at line 29, columns 9-16

     29 |         rightVs = drop (i+1) vs

  Whatever it is, it has a type that conforms to base.Map a b.
aryairani commented 4 years ago

Just ran into this again; here's another sample program in case it helps:

Stream.sum : '{Stream Nat} () -> Nat
Stream.sum =
  h : Nat -> Request {Stream Nat} () -> Nat
  h acc = cases
    { Stream.emit e -> resume} ->
      handle resume () with h (acc + e)
    { u } -> acc
  I'm not sure what _150003 means at line 3, columns 3-4

      3 |   h : Nat -> Request {Stream Nat} () -> Nat

  Whatever it is, it has a type that conforms to (.base.() ->{Stream .base.Nat} .base.()) -> .base.Nat.
ceedubs commented 2 years ago

I was just stumped for a bit on something similar.

While it's less likely to stump people in such a simple form you can get this message with something as simple as:

foo : Nat
foo =
  x = 3
  y = 4
  sum = x + y
  I'm not sure what _250003 means at line 5, columns 3-6

      5 |   sum = x + y

  Whatever it is, it has a type that conforms to Nat.

I think that there are two things going on here.

  1. Why does the user see _25003? Both _25003 and sum are highlighted red, so the compiler seems to know that it refers to sum. Are we able to show the user sum instead of _25003?
  2. Since this is pretty easy to accidentally do, it might be worth special-casing a binding at the end of a block for error messages. Maybe something like "Did you mean to return sum as the result of this expression? If so, add sum on a new line below line 5."