Simon Jakobi pushed to branch wip/sjakobi/T22637-v2 at Glasgow Haskell Compiler / GHC Commits: bcd7d99b by Simon Jakobi at 2026-04-10T18:53:13+02:00 Show multiple carets for TcRnBindingNameConflict When a name is bound multiple times (e.g. `f x x = 2`), the error now shows carets for all binding locations: TcRnBindingNameConflict.hs:3:3: error: [GHC-10498] • Conflicting definitions for 'x' Bound at: TcRnBindingNameConflict.hs:3:3 TcRnBindingNameConflict.hs:3:5 • In an equation for 'f' | 3 | f x x = 2 | ^ | 3 | f x x = 2 | ^ This is achieved by implementing `diagnosticSourceSpans` for `TcRnBindingNameConflict`, which already carries multiple source locations as `NonEmpty SrcSpan`. - - - - - d318c190 by Simon Jakobi at 2026-04-10T20:19:16+02:00 Update tests for multi-caret TcRnBindingNameConflict diagnostics Updated tests to use -fdiagnostics-show-caret now that TcRnBindingNameConflict shows carets for all binding locations: - rnfail004: Shows carets for 'a' and 'b' conflicts across lines - tcfail038: Shows carets for '==' and '/=' on different lines - T14114: Shows carets for both 'a' positions in pattern (a,a) - - - - - 7 changed files: - compiler/GHC/Tc/Errors/Ppr.hs - testsuite/tests/patsyn/should_fail/T14114.stderr - testsuite/tests/patsyn/should_fail/all.T - testsuite/tests/rename/should_fail/all.T - testsuite/tests/rename/should_fail/rnfail004.stderr - testsuite/tests/typecheck/should_fail/all.T - testsuite/tests/typecheck/should_fail/tcfail038.stderr Changes: ===================================== compiler/GHC/Tc/Errors/Ppr.hs ===================================== @@ -3479,6 +3479,11 @@ instance Diagnostic TcRnMessage where NE.fromList $ sortBy leftmost_smallest $ map (getLocA . fst) (NE.toList pairs) + TcRnBindingNameConflict _ locs + -> Just $ + NE.fromList $ + sortBy leftmost_smallest $ + NE.toList locs _ -> Nothing ===================================== testsuite/tests/patsyn/should_fail/T14114.stderr ===================================== @@ -1,18 +1,36 @@ T14114.hs:4:20: error: [GHC-10498] - • Conflicting definitions for ‘a’ + • Conflicting definitions for 'a' Bound at: T14114.hs:4:20 T14114.hs:4:22 • In a pattern synonym declaration + | +4 | pattern Foo1 a <- (a,a) + | ^ + | +4 | pattern Foo1 a <- (a,a) + | ^ T14114.hs:5:20: error: [GHC-10498] - • Conflicting definitions for ‘a’ + • Conflicting definitions for 'a' Bound at: T14114.hs:5:20 T14114.hs:5:22 • In a pattern synonym declaration + | +5 | pattern Foo2 a = (a,a) + | ^ + | +5 | pattern Foo2 a = (a,a) + | ^ T14114.hs:6:20: error: [GHC-10498] - • Conflicting definitions for ‘a’ + • Conflicting definitions for 'a' Bound at: T14114.hs:6:20 T14114.hs:6:22 • In a pattern synonym declaration + | +6 | pattern Foo3 a <- (a,a) where + | ^ + | +6 | pattern Foo3 a <- (a,a) where + | ^ ===================================== testsuite/tests/patsyn/should_fail/all.T ===================================== @@ -40,7 +40,7 @@ test('T26465', normal, compile_fail, ['']) test('T13349', normal, compile_fail, ['']) test('T13470', normal, compile_fail, ['']) test('T14112', normal, compile_fail, ['']) -test('T14114', normal, compile_fail, ['']) +test('T14114', normal, compile_fail, ['-fdiagnostics-show-caret']) test('T14507', normal, compile_fail, ['-dsuppress-uniques']) test('T15289', normal, compile_fail, ['']) test('T15685', normal, compile_fail, ['']) ===================================== testsuite/tests/rename/should_fail/all.T ===================================== @@ -1,7 +1,7 @@ test('rnfail001', normal, compile_fail, ['']) test('rnfail002', normal, compile_fail, ['']) test('rnfail003', normal, compile_fail, ['']) -test('rnfail004', normal, compile_fail, ['']) +test('rnfail004', normal, compile_fail, ['-fdiagnostics-show-caret']) test('rnfail007', normal, compile_fail, ['']) test('rnfail008', normal, compile_fail, ['']) test('rnfail009', normal, compile_fail, ['']) ===================================== testsuite/tests/rename/should_fail/rnfail004.stderr ===================================== @@ -1,10 +1,22 @@ -rnfail004.hs:6:5: [GHC-10498] - Conflicting definitions for ‘a’ +rnfail004.hs:6:5: error: [GHC-10498] + Conflicting definitions for 'a' Bound at: rnfail004.hs:6:5 rnfail004.hs:7:10 + | +6 | a = [] + | ^ + | +7 | (b,c,a) = ([],[],d) + | ^ -rnfail004.hs:7:6: [GHC-10498] - Conflicting definitions for ‘b’ +rnfail004.hs:7:6: error: [GHC-10498] + Conflicting definitions for 'b' Bound at: rnfail004.hs:7:6 rnfail004.hs:8:8 + | +7 | (b,c,a) = ([],[],d) + | ^ + | +8 | [d,b,_] = ([],a,[]) + | ^ ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -31,7 +31,7 @@ test('tcfail034', normal, compile_fail, ['']) test('tcfail035', normal, compile_fail, ['']) test('tcfail036', normal, compile_fail, ['']) test('tcfail037', normal, compile_fail, ['']) -test('tcfail038', normal, compile_fail, ['']) +test('tcfail038', normal, compile_fail, ['-fdiagnostics-show-caret']) test('tcfail040', normal, compile_fail, ['']) test('tcfail041', normal, compile_fail, ['']) test('tcfail042', normal, compile_fail, ['']) ===================================== testsuite/tests/typecheck/should_fail/tcfail038.stderr ===================================== @@ -1,10 +1,22 @@ -tcfail038.hs:7:11: [GHC-10498] - Conflicting definitions for ‘==’ +tcfail038.hs:7:11: error: [GHC-10498] + Conflicting definitions for '==' Bound at: tcfail038.hs:7:11-12 tcfail038.hs:9:11-12 + | +7 | a == b = True + | ^^ + | +9 | a == b = False + | ^^ -tcfail038.hs:8:11: [GHC-10498] - Conflicting definitions for ‘/=’ +tcfail038.hs:8:11: error: [GHC-10498] + Conflicting definitions for '/=' Bound at: tcfail038.hs:8:11-12 tcfail038.hs:10:11-12 + | + 8 | a /= b = False + | ^^ + | +10 | a /= b = True + | ^^ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5cfe2904db631ec407063166c32577... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5cfe2904db631ec407063166c32577... You're receiving this email because of your account on gitlab.haskell.org.