Simon Jakobi pushed to branch wip/sjakobi/multi-caret at Glasgow Haskell Compiler / GHC Commits: b71eabb0 by Simon Jakobi at 2026-06-11T14:33:13+02:00 Shorten Note [Choosing the primary and related spans] Per review by @sheaf: trim the note and present the last-occurrence-primary handling of duplicate diagnostics as current practice rather than a convention, noting that different diagnostics may pick and order their spans differently. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> - - - - - 1 changed file: - compiler/GHC/Types/Error.hs Changes: ===================================== compiler/GHC/Types/Error.hs ===================================== @@ -282,8 +282,7 @@ The rendering layer shows a diagnostic's locations in exactly the order given them is the message author's job: * Pick one real location as the primary span and list the rest as related - locations. The primary span need not be the leftmost or smallest location - involved; a synthetic span combining several locations is usually worse, + locations. A synthetic span combining several locations is usually worse, giving a less precise prefix and a larger caret. * Order the related spans deterministically (e.g. by sorting with @@ -291,19 +290,14 @@ them is the message author's job: natural order is not stable across runs. Do not repeat the primary span among them. - * Convention for "duplicate" diagnostics, which report the same entity - occurring at several sites (e.g. 'TcRnDuplicateDecls', - 'TcRnDuplicateExport'): the primary span is the /last/ occurrence in - source order; the earlier occurrences are the related locations, in - ascending order. The later occurrence is usually the one just added, and - hence the one to act on; clang, rustc and TypeScript likewise point at it - ("redefinition of 'x' / note: previous definition is here"). The carets - are then /not/ in source order, but read well without labels: first the - site to fix, then the prior sites. (Once per-span labels exist (#23414), - the renderer could instead display carets in source order, as rustc does — - its labels are what make that readable.) Diagnostics whose locations have - a different asymmetry (a definition site versus a use site, say) pick - their primary span on their own logic. +Different diagnostics may want to pick and order the spans in different ways. +For "duplicate" diagnostics, which report the same entity occurring at several +sites (e.g. 'TcRnDuplicateDecls', 'TcRnDuplicateExport'), we currently use the +/last/ occurrence in source order as the primary span, with the earlier +occurrences as related locations in ascending order: the last occurrence is +likely the one just added, and hence the most actionable; clang, rustc and +TypeScript likewise point at it ("redefinition of 'x' / note: previous +definition is here"). -} -- | A class identifying a diagnostic. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b71eabb0bbd7eb11787c7a0f7ce6e53a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b71eabb0bbd7eb11787c7a0f7ce6e53a... You're receiving this email because of your account on gitlab.haskell.org.