mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-04 01:03:36 +03:00
Now makes suggestions if the name matched but the type was different.
This commit is contained in:
parent
e9f978c9a7
commit
f0746a142e
@ -380,13 +380,16 @@ renderTypeError env e src = case e of
|
||||
where
|
||||
wrongTypeText pl = mconcat
|
||||
[ "I found " , pl "a term" "some terms" , " in scope with " , pl "a " ""
|
||||
, "matching name" , pl "" "s" , " but " , "the wrong type. "
|
||||
, "Maybe you meant " , pl "this" "one of these" , ":\n\n"
|
||||
, "matching name" , pl "" "s" , " but " , pl "a " "", "different type"
|
||||
, pl "" "s" , ". ", "If " , pl "this" "one of these"
|
||||
, " is what you meant, try using the fully qualified name and I might "
|
||||
, "be able to give you a more illuminating error message: \n\n"
|
||||
]
|
||||
wrongNameText pl = mconcat
|
||||
[ "I found " , pl "a term" "some terms" , " in scope with " , pl "a " ""
|
||||
, "matching type" , pl "" "s" , " but " , "the wrong name. "
|
||||
, "Maybe you meant " , pl "this" "one of these" , ":\n\n"
|
||||
, "matching type" , pl "" "s" , " but " , pl "a " "", "different name"
|
||||
, pl "" "s" , ". ", "Maybe you meant " , pl "this" "one of these"
|
||||
, ":\n\n"
|
||||
]
|
||||
formatSuggestion :: (Text, C.Type v loc) -> AT.AnnotatedDocument Color.Style
|
||||
formatSuggestion (name, typ) =
|
||||
|
@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE ViewPatterns #-}
|
||||
{-# LANGUAGE DoAndIfThenElse #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
@ -215,16 +216,17 @@ typeDirectedNameResolution resultSoFar env = do
|
||||
)
|
||||
guard x a = if x then Just a else Nothing
|
||||
substSuggestion :: Resolution v loc -> TDNR f v loc ()
|
||||
substSuggestion (Resolution _ _ loc [Context.Suggestion fqn _ builtin]) =
|
||||
let
|
||||
f t =
|
||||
guard (ABT.annotation t == loc)
|
||||
$ (if builtin
|
||||
then Term.ref loc . Builtin
|
||||
else Term.var loc . Var.named
|
||||
)
|
||||
fqn
|
||||
in pure <$> modify (ABT.visitPure f)
|
||||
substSuggestion (Resolution _ _ loc (filter Context.isExact ->
|
||||
[Context.Suggestion fqn _ builtin]))
|
||||
= let
|
||||
f t =
|
||||
guard (ABT.annotation t == loc)
|
||||
$ (if builtin
|
||||
then Term.ref loc . Builtin
|
||||
else Term.var loc . Var.named
|
||||
)
|
||||
fqn
|
||||
in pure <$> modify (ABT.visitPure f)
|
||||
substSuggestion _ = pure $ pure ()
|
||||
-- Returns Nothing for irrelevant notes
|
||||
resolveNote
|
||||
|
@ -28,6 +28,7 @@ module Unison.Typechecker.Context
|
||||
, apply
|
||||
, isSubtype
|
||||
, Suggestion(..)
|
||||
, isExact
|
||||
)
|
||||
where
|
||||
|
||||
@ -153,6 +154,10 @@ data Suggestion v loc =
|
||||
}
|
||||
deriving Show
|
||||
|
||||
isExact :: Suggestion v loc -> Bool
|
||||
isExact (Suggestion _ _ _) = True
|
||||
isExact _ = False
|
||||
|
||||
data Cause v loc
|
||||
= TypeMismatch (Context v loc)
|
||||
| IllFormedType (Context v loc)
|
||||
|
1
unison-src/errors/tdnr2.u
Normal file
1
unison-src/errors/tdnr2.u
Normal file
@ -0,0 +1 @@
|
||||
2.0 + 4
|
Loading…
Reference in New Issue
Block a user