on master help sign in
Emphasize missing arguments better in type diffs
ecd68b3Evan Czaplicki
src/Reporting/Render/Type.hs+44−21
@@ -169,19 +169,21 @@ diff localizer context leftType rightType =
169 go = diff localizer
169 go = diff localizer
170 in
170 in
171 case (leftType, rightType) of
171 case (leftType, rightType) of
172− (Type.Lambda _ _, Type.Lambda _ _) ->
172+ (Type.Aliased leftName leftArgs _, Type.Aliased rightName rightArgs _) | leftName == rightName ->
173− let
173+ docAppHelp localizer context leftName
174− leftParts = Type.collectLambdas leftType
174+ <$> sequenceA (zipWith (go App) (map snd leftArgs) (map snd rightArgs))
175− rightParts = Type.collectLambdas rightType
176− in
177
175
178− if length leftParts /= length rightParts then
176+ (Type.Aliased _ args real, _) ->
179− difference
177+ go context (Type.dealias args real) rightType
180− (docLambda context (map (docType localizer Func) leftParts))
181− (docLambda context (map (docType localizer Func) rightParts))
182
178
183− else
179+ (_, Type.Aliased _ args real) ->
184− docLambda context <$> sequenceA (zipWith (go Func) leftParts rightParts)
180+ go context leftType (Type.dealias args real)
181+
182+ (Type.Lambda _ _, _) ->
183+ diffLambda localizer context leftType rightType
184+
185+ (_, Type.Lambda _ _) ->
186+ diffLambda localizer context leftType rightType
185
187
186 (Type.Var x, Type.Var y) | x == y ->
188 (Type.Var x, Type.Var y) | x == y ->
187 pure (text x)
189 pure (text x)
@@ -216,16 +218,6 @@ diff localizer context leftType rightType =
216 in
218 in
217 diffRecord localizer leftFields leftExt rightFields rightExt
219 diffRecord localizer leftFields leftExt rightFields rightExt
218
220
219− (Type.Aliased leftName leftArgs _, Type.Aliased rightName rightArgs _) | leftName == rightName ->
220− docAppHelp localizer context leftName
221− <$> sequenceA (zipWith (go App) (map snd leftArgs) (map snd rightArgs))
222−
223− (Type.Aliased _ args real, _) ->
224− go context (Type.dealias args real) rightType
225−
226− (_, Type.Aliased _ args real) ->
227− go context leftType (Type.dealias args real)
228−
229 (_, _) ->
221 (_, _) ->
230 difference
222 difference
231 (docType localizer context leftType)
223 (docType localizer context leftType)
@@ -238,6 +230,37 @@ difference leftDoc rightDoc =
238
230
239
231
240
232
233+-- FUNCTION DIFFS
234+
235+
236+diffLambda :: Localizer -> Context -> Type.Canonical -> Type.Canonical -> Diff Doc
237+diffLambda localizer context leftType rightType =
238+ let
239+ leftArgs = reverse $ Type.collectLambdas leftType
240+ rightArgs = reverse $ Type.collectLambdas rightType
241+
242+ extraToDoc types =
243+ map (dullyellow . docType localizer Func) types
244+
245+ extraLefts = reverse $ extraToDoc $ drop (length rightArgs) leftArgs
246+ extraRights = reverse $ extraToDoc $ drop (length leftArgs) rightArgs
247+
248+ alignedArgDiff =
249+ reverse <$> sequenceA (zipWith (diff localizer Func) leftArgs rightArgs)
250+ in
251+ docLambda context <$>
252+ case (extraLefts, extraRights, alignedArgDiff) of
253+ ([], [], _) ->
254+ alignedArgDiff
255+
256+ (_, _, Same docs) ->
257+ Diff (extraLefts ++ docs) (extraRights ++ docs)
258+
259+ (_, _, Diff lefts rights) ->
260+ Diff (extraLefts ++ lefts) (extraRights ++ rights)
261+
262+
263+
241-- RECORD DIFFS
264-- RECORD DIFFS
242
265
243
266