diff --git a/lib/unison-pretty-printer/src/Unison/Util/Pretty.hs b/lib/unison-pretty-printer/src/Unison/Util/Pretty.hs index 474fb88383..c19c030142 100644 --- a/lib/unison-pretty-printer/src/Unison/Util/Pretty.hs +++ b/lib/unison-pretty-printer/src/Unison/Util/Pretty.hs @@ -229,7 +229,7 @@ wrapImplPreserveSpaces = \case (Lit s) -> fromMaybe False (fmap (isSpaceNotNewline . fst) $ LL.uncons s) _ -> False f p | startsWithSpace p = p `orElse` newline - f p = p + f p = p `orElse` (newline <> p) isSpaceNotNewline :: Char -> Bool isSpaceNotNewline c = isSpace c && not (c == '\n') diff --git a/parser-typechecker/src/Unison/PrintError.hs b/parser-typechecker/src/Unison/PrintError.hs index d3174ce657..96528b8547 100644 --- a/parser-typechecker/src/Unison/PrintError.hs +++ b/parser-typechecker/src/Unison/PrintError.hs @@ -4,10 +4,12 @@ module Unison.PrintError where import Control.Lens ((%~)) import Control.Lens.Tuple (_1, _2, _3) -import Data.List (find, intersperse) +import Data.Function (on) +import Data.List (find, intersperse, sortBy) import Data.List.Extra (nubOrd) import Data.List.NonEmpty qualified as Nel import Data.Map qualified as Map +import Data.Ord (comparing) import Data.Proxy import Data.Sequence (Seq (..)) import Data.Set qualified as Set @@ -35,7 +37,7 @@ import Unison.Prelude import Unison.PrettyPrintEnv qualified as PPE import Unison.PrettyPrintEnv.Names qualified as PPE import Unison.Reference qualified as R -import Unison.Referent (Referent, pattern Ref) +import Unison.Referent (Referent, toReference, pattern Ref) import Unison.Result (Note (..)) import Unison.Result qualified as Result import Unison.Settings qualified as Settings @@ -171,9 +173,8 @@ renderTypeError :: TypeError v loc -> Env -> String -> - Path.Absolute -> Pretty ColorText -renderTypeError e env src curPath = case e of +renderTypeError e env src = case e of BooleanMismatch {..} -> mconcat [ Pr.wrap $ @@ -629,51 +630,112 @@ renderTypeError e env src curPath = case e of _ -> Pr.wrap $ "It should be of type " <> Pr.group (style Type1 (renderType' env expectedType) <> ".") UnknownTerm {..} -> let (correct, wrongTypes, wrongNames) = - foldr sep id suggestions ([], [], []) - sep (C.Suggestion name typ _ match) r = + foldr + sep + id + ( sortBy + ( comparing length <> compare + `on` (Text.splitOn "." . C.suggestionName) + ) + suggestions + ) + ([], [], []) + sep s@(C.Suggestion _ _ _ match) r = case match of - C.Exact -> (_1 %~ ((name, typ) :)) . r - C.WrongType -> (_2 %~ ((name, typ) :)) . r - C.WrongName -> (_3 %~ ((name, typ) :)) . r - libPath = Path.absoluteToPath' curPath Path.:> "lib" + C.Exact -> (_1 %~ (s :)) . r + C.WrongType -> (_2 %~ (s :)) . r + C.WrongName -> (_3 %~ (s :)) . r + undefinedSymbolHelp = + mconcat + [ ( case expectedType of + Type.Var' (TypeVar.Existential {}) -> + Pr.wrap "I also don't know what type it should be." + _ -> + mconcat + [ Pr.wrap "I think its type should be:", + "\n\n", + Pr.indentN 4 (style Type1 (renderType' env expectedType)) + ] + ), + "\n\n", + Pr.hang + "Some common causes of this error include:" + ( Pr.bulleted + [ Pr.wrap "Your current namespace is too deep to contain the definition in its subtree", + Pr.wrap "The definition is part of a library which hasn't been added to this project", + Pr.wrap "You have a typo in the name" + ] + ) + ] in mconcat - [ "I couldn't find any definitions matching the name ", + [ "I couldn't figure out what ", style ErrorSite (Var.nameStr unknownTermV), - " inside the namespace ", - prettyPath' (Path.absoluteToPath' curPath), - "\n\n", + " refers to here:\n\n", annotatedAsErrorSite src termSite, "\n", - Pr.hang - "Some common causes of this error include:" - ( Pr.bulleted - [ Pr.wrap "Your current namespace is too deep to contain the definition in its subtree", - Pr.wrap "The definition is part of a library which hasn't been added to this project" - ] - ) - <> "\n\n" - <> "To add a library to this project use the command: " - <> Pr.backticked ("fork <.path.to.lib> " <> Pr.shown (libPath Path.:> "")), - "\n\n", - case expectedType of - Type.Var' (TypeVar.Existential {}) -> "There are no constraints on its type." - _ -> - "Whatever it is, its type should conform to " - <> style Type1 (renderType' env expectedType) - <> ".", - "\n\n", - -- ++ showTypeWithProvenance env src Type1 expectedType case correct of [] -> case wrongTypes of [] -> case wrongNames of - [] -> mempty + [] -> undefinedSymbolHelp wrongs -> formatWrongs wrongNameText wrongs - wrongs -> formatWrongs wrongTypeText wrongs + wrongs -> + let helpMeOut = + Pr.wrap + ( mconcat + [ "Help me out by", + Pr.bold "using a more specific name here", + "or", + Pr.bold "adding a type annotation." + ] + ) + in Pr.wrap + ( "The name " + <> style Identifier (Var.nameStr unknownTermV) + <> " is ambiguous. I tried to resolve it by type but" + ) + <> " " + <> case expectedType of + Type.Var' (TypeVar.Existential {}) -> Pr.wrap ("its type could be anything." <> helpMeOut) <> "\n" + _ -> + mconcat + [ ( Pr.wrap $ + mconcat + [ "no term with that name would pass typechecking.", + "I think its type should be:" + ] + ), + "\n\n", + Pr.indentN 4 (style Type1 (renderType' env expectedType)), + "\n\n", + Pr.wrap + ( mconcat + [ "If that's not what you expected, you may have a type error somewhere else in your code.", + helpMeOut + ] + ) + ] + <> "\n\n" + <> formatWrongs wrongTypeText wrongs suggs -> mconcat - [ "I found some terms in scope that have matching names and types. ", - "Maybe you meant one of these:\n\n", - intercalateMap "\n" formatSuggestion suggs + [ Pr.wrap + ( mconcat + [ mconcat + [ "The name ", + style Identifier (Var.nameStr unknownTermV), + " is ambiguous. " + ], + case expectedType of + Type.Var' (TypeVar.Existential {}) -> "I couldn't narrow it down by type, as any type would work here." + _ -> + "Its type should be:\n\n" + <> Pr.indentN 4 (style Type1 (renderType' env expectedType)) + ] + ), + "\n\n", + Pr.wrap "I found some terms in scope that have matching names and types. Maybe you meant one of these:", + "\n\n", + intercalateMap "\n" (renderSuggestion env) suggs ] ] DuplicateDefinitions {..} -> @@ -735,47 +797,48 @@ renderTypeError e env src curPath = case e of ] where wrongTypeText pl = - mconcat - [ "I found ", - pl "a term" "some terms", - " in scope with ", - pl "a " "", - "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" - ] + Pr.paragraphyText + ( mconcat + [ "I found ", + pl "a term" "some terms", + " in scope with ", + pl "a " "", + "matching name", + pl "" "s", + " but ", + pl "a " "", + "different type", + pl "" "s", + ". ", + "If ", + pl "this" "one of these", + " is what you meant, try using its full name:" + ] + ) + <> "\n\n" wrongNameText pl = - mconcat - [ "I found ", - pl "a term" "some terms", - " in scope with ", - pl "a " "", - "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) -> Pretty ColorText - formatSuggestion (name, typ) = - " - " <> fromString (Text.unpack name) <> " : " <> renderType' env typ + Pr.paragraphyText + ( mconcat + [ "I found ", + pl "a term" "some terms", + " in scope with ", + pl "a " "", + "matching type", + pl "" "s", + " but ", + pl "a " "", + "different name", + pl "" "s", + ". ", + "Maybe you meant ", + pl "this" "one of these", + ":\n\n" + ] + ) formatWrongs txt wrongs = let sz = length wrongs pl a b = if sz == 1 then a else b - in mconcat [txt pl, intercalateMap "\n" formatSuggestion wrongs] + in mconcat [txt pl, intercalateMap "\n" (renderSuggestion env) wrongs] ordinal :: (IsString s) => Int -> s ordinal n = fromString $ @@ -1134,7 +1197,12 @@ renderType env f t = renderType0 env f (0 :: Int) (cleanup t) renderSuggestion :: (IsString s, Semigroup s, Var v) => Env -> C.Suggestion v loc -> s renderSuggestion env sug = - fromString (Text.unpack $ C.suggestionName sug) + renderTerm + env + ( case C.suggestionReplacement sug of + Right ref -> Term.ref () (toReference ref) + Left v -> Term.var () v + ) <> " : " <> renderType' env @@ -1242,10 +1310,9 @@ renderNoteAsANSI :: Pr.Width -> Env -> String -> - Path.Absolute -> Note v a -> String -renderNoteAsANSI w e s curPath n = Pr.toANSI w $ printNoteWithSource e s curPath n +renderNoteAsANSI w e s n = Pr.toANSI w $ printNoteWithSource e s n renderParseErrorAsANSI :: (Var v) => Pr.Width -> String -> Parser.Err v -> String renderParseErrorAsANSI w src = Pr.toANSI w . prettyParseError src @@ -1254,19 +1321,18 @@ printNoteWithSource :: (Var v, Annotated a, Show a, Ord a) => Env -> String -> - Path.Absolute -> Note v a -> Pretty ColorText -printNoteWithSource env _s _curPath (TypeInfo n) = prettyTypeInfo n env -printNoteWithSource _env s _curPath (Parsing e) = prettyParseError s e -printNoteWithSource env s curPath (TypeError e) = prettyTypecheckError e env s curPath -printNoteWithSource _env _s _curPath (NameResolutionFailures _es) = undefined -printNoteWithSource _env s _curPath (UnknownSymbol v a) = +printNoteWithSource env _s (TypeInfo n) = prettyTypeInfo n env +printNoteWithSource _env s (Parsing e) = prettyParseError s e +printNoteWithSource env s (TypeError e) = prettyTypecheckError e env s +printNoteWithSource _env _s (NameResolutionFailures _es) = undefined +printNoteWithSource _env s (UnknownSymbol v a) = fromString ("Unknown symbol `" ++ Text.unpack (Var.name v) ++ "`\n\n") <> annotatedAsErrorSite s a -printNoteWithSource env s _curPath (CompilerBug (Result.TypecheckerBug c)) = +printNoteWithSource env s (CompilerBug (Result.TypecheckerBug c)) = renderCompilerBug env s c -printNoteWithSource _env _s _curPath (CompilerBug c) = +printNoteWithSource _env _s (CompilerBug c) = fromString $ "Compiler bug: " <> show c _printPosRange :: String -> L.Pos -> L.Pos -> String @@ -1877,10 +1943,9 @@ prettyTypecheckError :: C.ErrorNote v loc -> Env -> String -> - Path.Absolute -> Pretty ColorText -prettyTypecheckError note env src curPath = - renderTypeError (typeErrorFromNote note) env src curPath +prettyTypecheckError note env src = + renderTypeError (typeErrorFromNote note) env src prettyTypeInfo :: (Var v, Ord loc, Show loc, Parser.Annotated loc) => diff --git a/parser-typechecker/src/Unison/Runtime/IOSource.hs b/parser-typechecker/src/Unison/Runtime/IOSource.hs index 8286a525c4..670484a0a2 100644 --- a/parser-typechecker/src/Unison/Runtime/IOSource.hs +++ b/parser-typechecker/src/Unison/Runtime/IOSource.hs @@ -12,7 +12,6 @@ import Text.RawString.QQ (r) import Unison.Builtin qualified as Builtin import Unison.Codebase.CodeLookup (CodeLookup (..)) import Unison.Codebase.CodeLookup.Util qualified as CL -import Unison.Codebase.Path qualified as Path import Unison.ConstructorReference (GConstructorReference (..)) import Unison.DataDeclaration qualified as DD import Unison.DataDeclaration.ConstructorId qualified as DD @@ -1002,7 +1001,7 @@ type EitherResult = Either String TFile showNotes :: (Foldable f) => String -> PrintError.Env -> f Note -> String showNotes source env = - intercalateMap "\n\n" $ PrintError.renderNoteAsANSI 60 env source Path.absoluteEmpty + intercalateMap "\n\n" $ PrintError.renderNoteAsANSI 60 env source ppEnv :: PPE.PrettyPrintEnv ppEnv = PPE.makePPE (PPE.hqNamer 10 Builtin.names) PPE.dontSuffixify diff --git a/parser-typechecker/tests/Unison/Test/UnisonSources.hs b/parser-typechecker/tests/Unison/Test/UnisonSources.hs index e63945d3ce..9c4968d034 100644 --- a/parser-typechecker/tests/Unison/Test/UnisonSources.hs +++ b/parser-typechecker/tests/Unison/Test/UnisonSources.hs @@ -10,7 +10,6 @@ import System.Directory (doesFileExist) import System.FilePath (joinPath, replaceExtension, splitPath) import System.FilePath.Find (always, extension, find, (==?)) import Unison.Builtin qualified as Builtin -import Unison.Codebase.Path qualified as Path import Unison.Codebase.Runtime (Runtime, evaluateWatches) import Unison.NamesWithHistory qualified as Names import Unison.Parser.Ann (Ann) @@ -89,7 +88,7 @@ go rt files how = do showNotes :: (Foldable f) => String -> PrintError.Env -> f Note -> String showNotes source env = - intercalateMap "\n\n" $ PrintError.renderNoteAsANSI 60 env source Path.absoluteEmpty + intercalateMap "\n\n" $ PrintError.renderNoteAsANSI 60 env source decodeResult :: String -> SynthResult -> EitherResult -- String (UF.TypecheckedUnisonFile Symbol Ann) diff --git a/unison-cli/src/Unison/CommandLine/OutputMessages.hs b/unison-cli/src/Unison/CommandLine/OutputMessages.hs index 69adaba9ec..e41b0ced0d 100644 --- a/unison-cli/src/Unison/CommandLine/OutputMessages.hs +++ b/unison-cli/src/Unison/CommandLine/OutputMessages.hs @@ -1120,11 +1120,11 @@ notifyUser dir = \case ] ParseErrors src es -> pure . P.sep "\n\n" $ prettyParseError (Text.unpack src) <$> es - TypeErrors curPath src ppenv notes -> do + TypeErrors _curPath src ppenv notes -> do let showNote = - intercalateMap "\n\n" (printNoteWithSource ppenv (Text.unpack src) curPath) + intercalateMap "\n\n" (printNoteWithSource ppenv (Text.unpack src)) . map Result.TypeError - pure . showNote $ notes + pure $ showNote notes CompilerBugs src env bugs -> pure $ intercalateMap "\n\n" bug bugs where bug = renderCompilerBug env (Text.unpack src) @@ -2296,30 +2296,30 @@ prettyUploadEntitiesError = \case prettyValidationFailure :: Share.EntityValidationError -> Pretty prettyValidationFailure = \case - Share.EntityHashMismatch entityType (Share.HashMismatchForEntity{supplied, computed}) -> - P.lines - [ P.wrap $ "The hash associated with the given " <> prettyEntityType entityType <> " entity is incorrect.", - "", - P.wrap $ "The associated hash is: " <> prettyHash32 supplied, - P.wrap $ "The computed hash is: " <> prettyHash32 computed - ] - Share.UnsupportedEntityType hash32 entityType -> - P.lines - [ P.wrap $ "The entity with hash " <> prettyHash32 hash32 <> " of type " <> prettyEntityType entityType <> " is not supported by your version of ucm.", - P.wrap $ "Try upgrading to the latest version of ucm." - ] - Share.InvalidByteEncoding hash32 entityType msg -> - P.lines - [ P.wrap $ "Failed to decode a " <> prettyEntityType entityType <> " entity with the hash " <> prettyHash32 hash32 <> ".", - "Please create an issue and report this to the Unison team", - "", - P.wrap $ "The error was: " <> P.text msg - ] - Share.HashResolutionFailure hash32 -> - P.lines - [ P.wrap $ "Failed to resolve a referenced hash when validating the hash for " <> prettyHash32 hash32 <> ".", - "Please create an issue and report this to the Unison team" - ] + Share.EntityHashMismatch entityType (Share.HashMismatchForEntity {supplied, computed}) -> + P.lines + [ P.wrap $ "The hash associated with the given " <> prettyEntityType entityType <> " entity is incorrect.", + "", + P.wrap $ "The associated hash is: " <> prettyHash32 supplied, + P.wrap $ "The computed hash is: " <> prettyHash32 computed + ] + Share.UnsupportedEntityType hash32 entityType -> + P.lines + [ P.wrap $ "The entity with hash " <> prettyHash32 hash32 <> " of type " <> prettyEntityType entityType <> " is not supported by your version of ucm.", + P.wrap $ "Try upgrading to the latest version of ucm." + ] + Share.InvalidByteEncoding hash32 entityType msg -> + P.lines + [ P.wrap $ "Failed to decode a " <> prettyEntityType entityType <> " entity with the hash " <> prettyHash32 hash32 <> ".", + "Please create an issue and report this to the Unison team", + "", + P.wrap $ "The error was: " <> P.text msg + ] + Share.HashResolutionFailure hash32 -> + P.lines + [ P.wrap $ "Failed to resolve a referenced hash when validating the hash for " <> prettyHash32 hash32 <> ".", + "Please create an issue and report this to the Unison team" + ] where prettyEntityType = \case Share.TermComponentType -> "term component" @@ -2737,7 +2737,7 @@ renderEditConflicts ppe Patch {..} = do then "deprecated and also replaced with" else "replaced with" ) - `P.hang` P.lines replacements + `P.hang` P.lines replacements formatTermEdits :: (Reference.TermReference, Set TermEdit.TermEdit) -> Numbered Pretty @@ -2752,7 +2752,7 @@ renderEditConflicts ppe Patch {..} = do then "deprecated and also replaced with" else "replaced with" ) - `P.hang` P.lines replacements + `P.hang` P.lines replacements formatConflict :: Either (Reference, Set TypeEdit.TypeEdit) diff --git a/unison-cli/src/Unison/LSP/FileAnalysis.hs b/unison-cli/src/Unison/LSP/FileAnalysis.hs index ab3295488b..0bd24a03f0 100644 --- a/unison-cli/src/Unison/LSP/FileAnalysis.hs +++ b/unison-cli/src/Unison/LSP/FileAnalysis.hs @@ -27,7 +27,6 @@ import Unison.ABT qualified as ABT import Unison.Cli.TypeCheck (computeTypecheckingEnvironment) import Unison.Cli.UniqueTypeGuidLookup qualified as Cli import Unison.Codebase qualified as Codebase -import Unison.Codebase.Path qualified as Path import Unison.DataDeclaration qualified as DD import Unison.Debug qualified as Debug import Unison.FileParsers (ShouldUseTndr (..)) @@ -208,7 +207,6 @@ getTokenMap tokens = analyseNotes :: (Foldable f) => Uri -> PrettyPrintEnv -> String -> f (Note Symbol Ann) -> Lsp ([Diagnostic], [RangedCodeAction]) analyseNotes fileUri ppe src notes = do - currentPath <- getCurrentPath flip foldMapM notes \note -> case note of Result.TypeError errNote@(Context.ErrorNote {cause}) -> do let typeErr = TypeError.typeErrorFromNote errNote @@ -262,7 +260,7 @@ analyseNotes fileUri ppe src notes = do shouldHaveBeenHandled e = do Debug.debugM Debug.LSP "This diagnostic should have been handled by a previous case but was not" e empty - diags = noteDiagnostic currentPath note ranges + diags = noteDiagnostic note ranges -- Sort on match accuracy first, then name. codeActions <- case cause of Context.UnknownTerm _ v suggestions typ -> do @@ -274,7 +272,7 @@ analyseNotes fileUri ppe src notes = do pure (diags, codeActions) Result.NameResolutionFailures {} -> do -- TODO: diagnostics/code actions for resolution failures - pure (noteDiagnostic currentPath note todoAnnotation, []) + pure (noteDiagnostic note todoAnnotation, []) Result.Parsing err -> do let diags = do (errMsg, ranges) <- PrintError.renderParseErrors src err @@ -284,7 +282,7 @@ analyseNotes fileUri ppe src notes = do -- TODO: Some parsing errors likely have reasonable code actions pure (diags, []) Result.UnknownSymbol _ loc -> - pure (noteDiagnostic currentPath note (singleRange loc), []) + pure (noteDiagnostic note (singleRange loc), []) Result.TypeInfo {} -> -- No relevant diagnostics from type info. pure ([], []) @@ -307,7 +305,7 @@ analyseNotes fileUri ppe src notes = do Context.UnknownExistentialVariable _sym _con -> todoAnnotation Context.IllegalContextExtension _con _el _s -> todoAnnotation Context.OtherBug _s -> todoAnnotation - pure (noteDiagnostic currentPath note ranges, []) + pure (noteDiagnostic note ranges, []) where -- Diagnostics with this return value haven't been properly configured yet. todoAnnotation = [] @@ -325,7 +323,6 @@ analyseNotes fileUri ppe src notes = do withNeighbours (a : as) = (a, as) : (second (a :) <$> withNeighbours as) -- Builds diagnostics for a note, one diagnostic per range. noteDiagnostic :: - Path.Absolute -> Note Symbol Ann -> -- All ranges affected by this note, each range may have references to 'related' -- ranges. @@ -333,8 +330,8 @@ analyseNotes fileUri ppe src notes = do -- other conflicted name locations. [(Range, [(Text, Range)])] -> [Diagnostic] - noteDiagnostic currentPath note ranges = - let msg = Text.pack $ Pretty.toPlain 80 $ PrintError.printNoteWithSource ppe src currentPath note + noteDiagnostic note ranges = + let msg = Text.pack $ Pretty.toPlain 80 $ PrintError.printNoteWithSource ppe src note in do (range, references) <- ranges pure $ mkDiagnostic fileUri range DiagnosticSeverity_Error msg references diff --git a/unison-src/transcripts-manual/rewrites.output.md b/unison-src/transcripts-manual/rewrites.output.md index e082410087..c0cd55be75 100644 --- a/unison-src/transcripts-manual/rewrites.output.md +++ b/unison-src/transcripts-manual/rewrites.output.md @@ -306,21 +306,18 @@ Instead, it should be an unbound free variable, which doesn't typecheck: Loading changes detected in scratch.u. - I couldn't find any definitions matching the name bar21 inside the namespace . + I couldn't figure out what bar21 refers to here: 19 | bar21 + I also don't know what type it should be. + Some common causes of this error include: * Your current namespace is too deep to contain the definition in its subtree * The definition is part of a library which hasn't been added to this project - - To add a library to this project use the command: `fork <.path.to.lib> .lib.` - - There are no constraints on its type. - - + * You have a typo in the name ``` In this example, the `a` is locally bound by the rule, so it shouldn't capture the `a = 39494` binding which is in scope at the point of the replacement: @@ -366,21 +363,18 @@ The `a` introduced will be freshened to not capture the `a` in scope, so it rema Loading changes detected in scratch.u. - I couldn't find any definitions matching the name a1 inside the namespace . + I couldn't figure out what a1 refers to here: 6 | a1 + I also don't know what type it should be. + Some common causes of this error include: * Your current namespace is too deep to contain the definition in its subtree * The definition is part of a library which hasn't been added to this project - - To add a library to this project use the command: `fork <.path.to.lib> .lib.` - - There are no constraints on its type. - - + * You have a typo in the name ``` ## Structural find diff --git a/unison-src/transcripts/destructuring-binds.output.md b/unison-src/transcripts/destructuring-binds.output.md index 970cd641cf..af097fc522 100644 --- a/unison-src/transcripts/destructuring-binds.output.md +++ b/unison-src/transcripts/destructuring-binds.output.md @@ -86,21 +86,20 @@ ex4 = Loading changes detected in scratch.u. - I couldn't find any definitions matching the name a inside the namespace . + I couldn't figure out what a refers to here: 2 | (a,b) = (a Nat.+ b, 19) + I think its type should be: + + Nat + Some common causes of this error include: * Your current namespace is too deep to contain the definition in its subtree * The definition is part of a library which hasn't been added to this project - - To add a library to this project use the command: `fork <.path.to.lib> .lib.` - - Whatever it is, its type should conform to Nat. - - + * You have a typo in the name ``` Even though the parser accepts any pattern on the LHS of a bind, it looks pretty weird to see things like `12 = x`, so we avoid showing a destructuring bind when the LHS is a "literal" pattern (like `42` or "hi"). Again these examples wouldn't compile with coverage checking. diff --git a/unison-src/transcripts/doc-formatting.output.md b/unison-src/transcripts/doc-formatting.output.md index e77936ef16..d4c000906f 100644 --- a/unison-src/transcripts/doc-formatting.output.md +++ b/unison-src/transcripts/doc-formatting.output.md @@ -194,9 +194,10 @@ Note that because of the special treatment of the first line mentioned above, wh doc3 : Doc doc3 = - [: When Unison identifies a paragraph, it removes any newlines - from it before storing it, and then reflows the paragraph text - to fit the display window on display/view/edit. + [: When Unison identifies a paragraph, it removes any + newlines from it before storing it, and then reflows the + paragraph text to fit the display window on + display/view/edit. For these purposes, a paragraph is any sequence of non-empty lines that have zero indent (after the unindenting mentioned @@ -209,8 +210,8 @@ Note that because of the special treatment of the first line mentioned above, wh is not treated | either. Note that because of the special treatment of the first line - mentioned above, where its leading space is removed, it is always - treated as a paragraph. + mentioned above, where its leading space is removed, it is + always treated as a paragraph. :] ``` @@ -401,24 +402,25 @@ para line lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolo test1 : Doc test1 = - [: The internal logic starts to get hairy when you use the \@ - features, for example referencing a name like @List.take. Internally, - the text between each such usage is its own blob (blob ends here - --> @List.take), so paragraph reflow has to be aware of multiple - blobs to do paragraph reflow (or, more accurately, to do the - normalization step where newlines with a paragraph are removed.) - - Para to reflow: lorem ipsum dolor lorem ipsum dolor lorem ipsum - dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem - ipsum dolor ending in ref @List.take + [: The internal logic starts to get hairy when you use the + \@ features, for example referencing a name like @List.take. + Internally, the text between each such usage is its own blob + (blob ends here --> @List.take), so paragraph reflow has to + be aware of multiple blobs to do paragraph reflow (or, more + accurately, to do the normalization step where newlines with + a paragraph are removed.) + + Para to reflow: lorem ipsum dolor lorem ipsum dolor lorem + ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum + dolor lorem ipsum dolor ending in ref @List.take @List.take starting para lorem ipsum dolor lorem ipsum dolor - lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum - dolor lorem ipsum dolor. + lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem + ipsum dolor lorem ipsum dolor. - Middle of para: lorem ipsum dolor lorem ipsum dolor lorem ipsum - dolor @List.take lorem ipsum dolor lorem ipsum dolor lorem ipsum - dolor lorem ipsum dolor. + Middle of para: lorem ipsum dolor lorem ipsum dolor lorem + ipsum dolor @List.take lorem ipsum dolor lorem ipsum dolor + lorem ipsum dolor lorem ipsum dolor. - non-para line (@List.take) with ref @List.take Another non-para line @@ -426,22 +428,22 @@ para line lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolo - non-para line with ref @List.take before a para-line lorem ipsum dolor lorem ipsum dolor lorem - ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor - lorem ipsum dolor lorem ipsum dolor. + ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum + dolor lorem ipsum dolor lorem ipsum dolor. - non-para line followed by a para line starting with ref - @List.take lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor - lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum - dolor lorem ipsum dolor. + @List.take lorem ipsum dolor lorem ipsum dolor lorem ipsum + dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor + lorem ipsum dolor lorem ipsum dolor. - a para-line ending with ref lorem ipsum dolor lorem ipsum dolor - lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum - dolor lorem ipsum dolor lorem ipsum dolor @List.take + a para-line ending with ref lorem ipsum dolor lorem ipsum + dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor + lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor @List.take - non-para line - para line lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor - lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum - dolor lorem ipsum dolor + para line lorem ipsum dolor lorem ipsum dolor lorem ipsum + dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor + lorem ipsum dolor lorem ipsum dolor @List.take followed by non-para line starting with ref. @[signature] List.take diff --git a/unison-src/transcripts/docs.output.md b/unison-src/transcripts/docs.output.md index ff6e98f603..9fc30e1602 100644 --- a/unison-src/transcripts/docs.output.md +++ b/unison-src/transcripts/docs.output.md @@ -128,10 +128,10 @@ We can view it with `docs`, which shows the `Doc` value that is associated with ```ucm .builtin> docs List.take - `List.take n xs` returns the first `n` elements of `xs`. (No need - to add line breaks manually. The display command will do wrapping - of text for you. Indent any lines where you don't want it to do - this.) + `List.take n xs` returns the first `n` elements of `xs`. (No + need to add line breaks manually. The display command will do + wrapping of text for you. Indent any lines where you don't + want it to do this.) ## Examples: diff --git a/unison-src/transcripts/fix845.output.md b/unison-src/transcripts/fix845.output.md index 38a9888f10..fbdc9fc732 100644 --- a/unison-src/transcripts/fix845.output.md +++ b/unison-src/transcripts/fix845.output.md @@ -34,21 +34,20 @@ Now, typecheck a file with a reference to `Blah.zonk` (which doesn't exist in th Loading changes detected in scratch.u. - I couldn't find any definitions matching the name Blah.zonk inside the namespace . + I couldn't figure out what Blah.zonk refers to here: 2 | > Blah.zonk [1,2,3] + I think its type should be: + + [Nat] -> o + Some common causes of this error include: * Your current namespace is too deep to contain the definition in its subtree * The definition is part of a library which hasn't been added to this project - - To add a library to this project use the command: `fork <.path.to.lib> .lib.` - - Whatever it is, its type should conform to [Nat] -> o. - - + * You have a typo in the name ``` Here's another example, just checking that TDNR works for definitions in the same file: diff --git a/unison-src/transcripts/formatter.output.md b/unison-src/transcripts/formatter.output.md index bdc39c9302..904095a21d 100644 --- a/unison-src/transcripts/formatter.output.md +++ b/unison-src/transcripts/formatter.output.md @@ -99,25 +99,28 @@ brokenDoc = {{ hello }} + 1 Loading changes detected in scratch.u. - I couldn't find any definitions matching the name + inside the namespace . + I couldn't figure out what + refers to here: 1 | brokenDoc = {{ hello }} + 1 - Some common causes of this error include: - * Your current namespace is too deep to contain the - definition in its subtree - * The definition is part of a library which hasn't been - added to this project + The name + is ambiguous. I tried to resolve it by type but no + term with that name would pass typechecking. I think its type + should be: - To add a library to this project use the command: `fork <.path.to.lib> .lib.` + Doc2 -> Nat -> o - Whatever it is, its type should conform to Doc2 -> Nat -> o. + If that's not what you expected, you may have a type error + somewhere else in your code. + Help me out by using a more specific name here or adding a + type annotation. - I found some terms in scope with matching names but different types. If 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: + I found some terms in scope with matching names but different + types. If one of these is what you meant, try using its full + name: - - builtin.Float.+ : Float -> Float -> Float - - builtin.Int.+ : Int -> Int -> Int - - builtin.Nat.+ : Nat -> Nat -> Nat + (Float.+) : Float -> Float -> Float + (Int.+) : Int -> Int -> Int + (Nat.+) : Nat -> Nat -> Nat ``` ```ucm diff --git a/unison-src/transcripts/resolution-failures.output.md b/unison-src/transcripts/resolution-failures.output.md index af7a5f9b48..f90308358f 100644 --- a/unison-src/transcripts/resolution-failures.output.md +++ b/unison-src/transcripts/resolution-failures.output.md @@ -112,23 +112,17 @@ useAmbiguousTerm = ambiguousTerm Loading changes detected in scratch.u. - I couldn't find any definitions matching the name ambiguousTerm inside the namespace .example.resolution_failures + I couldn't figure out what ambiguousTerm refers to here: 1 | useAmbiguousTerm = ambiguousTerm - Some common causes of this error include: - * Your current namespace is too deep to contain the - definition in its subtree - * The definition is part of a library which hasn't been - added to this project + The name ambiguousTerm is ambiguous. I couldn't narrow it down + by type, as any type would work here. - To add a library to this project use the command: `fork <.path.to.lib> .example.resolution_failures.lib.` + I found some terms in scope that have matching names and + types. Maybe you meant one of these: - There are no constraints on its type. - - I found some terms in scope that have matching names and types. Maybe you meant one of these: - - - one.ambiguousTerm : ##Text - - two.ambiguousTerm : ##Text + one.ambiguousTerm : ##Text + two.ambiguousTerm : ##Text ```