Now makes suggestions if the name matched but the type was different.

This commit is contained in:
Runar Bjarnason 2018-10-11 21:49:01 -04:00
parent e9f978c9a7
commit f0746a142e
4 changed files with 25 additions and 14 deletions

View File

@ -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) =

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1 @@
2.0 + 4