After this commit, we have to use an explicit `discard` in code such as ``` def g (x : Nat) : IO Nat := ... def f (x : Nat) : IO Unit := do discard <| g x -- type error without the `discard` IO.println x ``` Motivation: prevent users from making mistakes such as ``` def f (xs : Array Nat) : IO Unit := do xs.set! 0 1 IO.println xs ``` when they meant to write ``` def f (xs : Array Nat) : IO Unit := do let xs := xs.set! 0 1 IO.println xs ```
30 lines
669 B
Text
30 lines
669 B
Text
doIssue.lean:2:2: error: application type mismatch
|
|
do
|
|
pure x
|
|
IO.println x
|
|
argument
|
|
fun (x_1 : PUnit) => IO.println x
|
|
has type
|
|
PUnit → IO Unit
|
|
but is expected to have type
|
|
Nat → IO Unit
|
|
doIssue.lean:10:2: error: application type mismatch
|
|
do
|
|
pure (Array.set! xs 0 1)
|
|
IO.println xs
|
|
argument
|
|
fun (x : PUnit) => IO.println xs
|
|
has type
|
|
PUnit → IO Unit
|
|
but is expected to have type
|
|
Array Nat → IO Unit
|
|
doIssue.lean:18:2: error: application type mismatch
|
|
do
|
|
pure (Array.set! xs 0 1)
|
|
IO.println xs
|
|
argument
|
|
fun (x : PUnit) => IO.println xs
|
|
has type
|
|
PUnit → IO Unit
|
|
but is expected to have type
|
|
Array Nat → IO Unit
|