8000 Better row unification error messages by FredTheDino · Pull Request #4421 · purescript/purescript · GitHub
[go: up one dir, main page]

Skip to content
8000
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4975df0
Try to show which labels are mismatched as well
FredTheDino Nov 29, 2022
47aff37
Revert "Try to show which labels are mismatched as well"
FredTheDino Dec 4, 2022
7b4c4d6
Display a merged error message
FredTheDino Dec 4, 2022
c0cd73d
Revert "Display a merged error message"
FredTheDino Dec 16, 2022
ef71d77
Add testcases for more record errors
FredTheDino Dec 19, 2022
b5e4f81
Add test output before changes
FredTheDino Dec 19, 2022
335b873
Change the error generation code
FredTheDino Dec 16, 2022
5969058
Change a sequence into a parU
FredTheDino Dec 16, 2022
3cb3074
Update the test output after changes
FredTheDino Dec 19, 2022
9c1c4f4
Add test for parU change
FredTheDino Dec 19, 2022
fe37bdc
Merge remote-tracking branch 'origin/master' into HEAD
MonoidMusician Feb 1, 2023
7041b93
Commit test changes from merge
MonoidMusician Feb 1, 2023
48c33f6
Merge remote-tracking branch 'origin/master' into types-do-not-unify-…
JordanMartinez Aug 7, 2023
03ba84a
Make types in error message different
JordanMartinez Aug 7, 2023
af8260b
Report both errors in nested error
JordanMartinez Aug 8, 2023
d4cf721
Test out substituteType approach
JordanMartinez Aug 8, 2023
fa7235f
Revert "Test out substituteType approach"
JordanMartinez Aug 8, 2023
ed9bcd9
Show `master`'s output of added tests
JordanMartinez Aug 8, 2023
0ae5f1f
Revert "Show `master`'s output of added tests"
JordanMartinez Aug 8, 2023
f9a8aad
Commit output of dropping `parU`
JordanMartinez Aug 8, 2023
7a160d4
Simplify using parU to get all errors
JordanMartinez Aug 8, 2023
48516ea
Merge remote-tracking branch 'origin/master' into types-do-not-unify-…
JordanMartinez Aug 8, 2023
958c954
Use `parU` to fix multi errors in 1 row test
JordanMartinez Aug 8, 2023
25b8c10
Add another test showing shared/unshared labels
JordanMartinez Aug 8, 2023
c7566f9
Cleanup comments
JordanMartinez Aug 8, 2023
f7ec585
Rework unifyRows error handling
rhendric Aug 8, 2023
cb9031a
Generalize unifyRows to unifyishRows
JordanMartinez Aug 9, 2023
5bae146
Update subsumes to use unifyishRows
JordanMartinez Aug 9, 2023
14702f7
Add Ryan's kind unification test
JordanMartinez Aug 9, 2023
f70c8d9
Update unifyKindsWithFailure to use unifyishRows sometimes
JordanMartinez Aug 9, 2023
93617e1
A little fussing before the action
rhendric Aug 10, 2023
5fa4ea0
Refactor record subsumption, unifyRows
rhendric Aug 10, 2023
8000 b80d3d3
Add used-x-expected-y bit to TypesDoNotUnify
rhendric Aug 10, 2023
de51a65
Rework checkProperties
rhendric Aug 10, 2023
28f4dff
Update tests
rhendric Aug 10, 2023
7202333
Error improvement: drop redundant subsumption hint
rhendric Aug 10, 2023
d02efa1
Error improvement: diff records like rows
rhendric Aug 10, 2023
6acdd99
Error improvement: display empty records as such
rhendric Aug 10, 2023
7ceba4c
Appease HLint
rhendric Aug 10, 2023
97b6b86
Update Kinds to always use unifyishRows
JordanMartinez Aug 10, 2023
9b54c4c
Use actual/expected terminology
JordanMartinez Aug 10, 2023
cee90c4
Merge remote-tracking branch 'origin/master' into better-unify-row-er…
JordanMartinez Aug 10, 2023
75aa382
First attempt at changelog entry
JordanMartinez Aug 10, 2023
09567b6
Update entry: apparent pattern matching inconsistency
JordanMartinez Aug 10, 2023
5b56006
Use 'expected but found' terminology
JordanMartinez Aug 10, 2023
6b60710
Use Ryan's suggestion to merge cases 2-4
JordanMartinez Aug 10, 2023
2094d75
Fix 'expected/actual' header text; reword opening
JordanMartinez Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Display a merged error message"
This reverts commit 7b4c4d6.
  • Loading branch information
FredTheDino committed Dec 19, 2022
commit c0cd73dfe973e411b04123cd7a3009b526f8f8ba
27 changes: 1 addition & 26 deletions src/Language/PureScript/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -846,12 +846,6 @@ prettyPrintSingleError (PPEOptions codeColor full level showDocs relPath fileCon
, line "has escaped its scope, appearing in the type"
, markCodeBox $ indent $ prettyType ty
]

renderSimpleErrorMessage (TypesDoNotUnify (r1@RCons{}) (r2@RCons{}))
= paras [ line "Failed to match row type"
, printRowsAsDiff (rowToList r1) (rowToList r2)
]

renderSimpleErrorMessage (TypesDoNotUnify u1 u2)
= let (row1Box, row2Box) = printRows u1 u2

Expand Down Expand Up @@ -1565,26 +1559,6 @@ prettyPrintSingleError (PPEOptions codeColor full level showDocs relPath fileCon
printRow f = markCodeBox . indent . f prettyDepth .
if full then id else eraseForAllKindAnnotations . eraseKindApps

-- NOTE: It might be hard to write anywhere that isn't top level, so keeping this a separate path for now.
printRowsAsDiff :: ([RowListItem a], Type a) -> ([RowListItem a], Type a) -> Box.Box
printRowsAsDiff (r1, ty1) (r2, _) =
printRow (rowsDiffAsInterlacedBox (mergeRows r1 r2)) ty1

mergeRows :: [RowListItem a] -> [RowListItem a] -> [(Label, Maybe (Type a), Maybe (Type a))]
mergeRows a b = merge (sort' a) (sort' b)
where
sort' = sortOn $ \(RowListItem _ name ty) -> (name, ty)

merge :: [RowListItem a] -> [RowListItem a] -> [(Label, Maybe (Type a), Maybe (Type a))]
merge s1@((RowListItem _ name1 ty1) : t1) s2@((RowListItem _ name2 ty2) : t2) =
case name1 `compare` name2 of
EQ | ty1 == ty2 -> merge t1 t2
EQ -> (name1, Just ty1, Just ty2) : merge t1 t2
LT -> (name1, Just ty1, Nothing ) : merge t1 s2
GT -> (name2, Nothing , Just ty2) : merge s1 t2
merge _ _ = []


-- If both rows are not empty, print them as diffs
-- If verbose print all rows else only print unique rows
printRows :: Type a -> Type a -> (Box.Box, Box.Box)
Expand All @@ -1597,6 +1571,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showDocs relPath fileCon

(_, _, _) -> (printRow typeAsBox r1, printRow typeAsBox r2)


-- Keep the unique labels only
filterRows :: ([RowListItem a], Type a) -> ([RowListItem a], Type a) -> (Type a, Type a)
filterRows (s1, r1) (s2, r2) =
Expand Down
35 changes: 0 additions & 35 deletions src/Language/PureScript/Pretty/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module Language.PureScript.Pretty.Types
, prettyPrintTypeAtom
, prettyPrintLabel
, prettyPrintObjectKey
, rowsDiffAsInterlacedBox
) where

import Prelude hiding ((<>))
Expand Down Expand Up @@ -145,34 +144,6 @@ prettyPrintRowWith tro open close labels rest =
tailToPs Nothing = nullBox
tailToPs (Just other) = text "| " <> typeAsBox' other

prettyPrintRowDiffWith :: TypeRenderOptions -> Char -> Char -> [(Label, Maybe PrettyPrintType, Maybe PrettyPrintType)] -> Box
prettyPrintRowDiffWith tro open close labels =
case labels of
[] | troRowAsDiff tro -> text [ open, ' ' ] <> text "..." <> text [ ' ', close ]
[] -> text [ open, close ]
_ ->
vcat left $
[ text [ open ] ]
++ fmap (\(name, ty1, ty2) -> nameAndTypeToPs name ty1 ty2) labels
++ catMaybes [ rowDiff, pure $ text [close] ]

where
nameAndTypeToPs :: Label -> Maybe PrettyPrintType -> Maybe PrettyPrintType -> Box
nameAndTypeToPs name maybeTy1 maybeTy2 =
let
format prefix ty = text ("," ++ prefix ++ T.unpack (prettyPrintLabel name) ++ " " ++ doubleColon ++ " ") <> typeAsBox' ty
in
vcat left $
[ fromMaybe (text "<no row>") $ fmap (format " ") maybeTy1
, fromMaybe (text "<no row>") $ fmap (format " ") maybeTy2
, text ""
]


doubleColon = if troUnicode tro then "∷" else "::"

rowDiff = if troRowAsDiff tro then Just (text "...") else Nothing

typeApp :: Pattern () PrettyPrintType (PrettyPrintType, PrettyPrintType)
typeApp = mkPattern match
where
Expand Down Expand Up @@ -291,12 +262,6 @@ typeDiffAsBox' = typeAsBoxImpl diffOptions
typeDiffAsBox :: Int -> Type a -> Box
typeDiffAsBox maxDepth = typeDiffAsBox' . convertPrettyPrintType maxDepth

rowsDiffAsInterlacedBox :: [(Label, Maybe (Type a), Maybe (Type a))] -> Int -> Type a -> Box
rowsDiffAsInterlacedBox merged maxDepth _ = prettyPrintRowDiffWith diffOptions '(' ')' mergedPretty
where
mergedPretty = fmap (\(name, ty1, ty2) -> (name, fmap prettyType ty1, fmap prettyType ty2)) merged
prettyType = convertPrettyPrintType maxDepth

data TypeRenderOptions = TypeRenderOptions
{ troSuggesting :: Bool
, troUnicode :: Bool
Expand Down
0