Simon Jakobi pushed to branch wip/sjakobi/multi-caret at Glasgow Haskell Compiler / GHC

Commits:

9 changed files:

Changes:

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -660,16 +660,16 @@ instance Diagnostic TcRnMessage where
    660 660
            $ formatExportItemError
    
    661 661
                (ppr export_item)
    
    662 662
                "attempts to export a default class declaration that is not visible here"
    
    663
    -    TcRnDuplicateExport gre ie1 ie2
    
    663
    +    TcRnDuplicateExport gre lie1 lie2
    
    664 664
           -> mkSimpleDecorated $
    
    665 665
                hsep [ quotes (ppr $ greName gre)
    
    666
    -                , text "is exported by", quotes (ppr ie1)
    
    667
    -                , text "and",            quotes (ppr ie2) ]
    
    668
    -    TcRnDuplicateNamedDefaultExport nm ie1 ie2
    
    669
    -      -> mkSimpleDecorated $
    
    670
    -           hsep [ text "The named default declaration for" <+> quotes (ppr nm)
    
    671
    -                , text "is exported by", quotes (ppr ie1)
    
    672
    -                , text "and",            quotes (ppr ie2) ]
    
    666
    +                , text "is exported by", quotes (ppr lie1)
    
    667
    +                , text "and",            quotes (ppr lie2) ]
    
    668
    +    TcRnDuplicateNamedDefaultExport nm lie1 lie2
    
    669
    +       -> mkSimpleDecorated $
    
    670
    +            hsep [ text "The named default declaration for" <+> quotes (ppr nm)
    
    671
    +                 , text "is exported by", quotes (ppr lie1)
    
    672
    +                 , text "and",            quotes (ppr lie2) ]
    
    673 673
         TcRnExportedParentChildMismatch parent_name ty_thing child parent_names
    
    674 674
           -> mkSimpleDecorated $
    
    675 675
                text "The type constructor" <+> quotes (ppr parent_name)
    
    ... ... @@ -3464,6 +3464,12 @@ instance Diagnostic TcRnMessage where
    3464 3464
           -> diagnosticRelatedLocations msg'
    
    3465 3465
         TcRnBindingNameConflict _ locs
    
    3466 3466
           -> NE.tail locs
    
    3467
    +    TcRnDuplicateDecls _ names
    
    3468
    +      -> map nameSrcSpan (NE.init names)
    
    3469
    +    TcRnDuplicateExport _ _lie1 lie2
    
    3470
    +      -> [getLocA lie2]
    
    3471
    +    TcRnDuplicateNamedDefaultExport _ _lie1 lie2
    
    3472
    +      -> [getLocA lie2]
    
    3467 3473
         _ ->
    
    3468 3474
           []
    
    3469 3475
     
    

  • compiler/GHC/Tc/Errors/Types.hs
    ... ... @@ -1607,14 +1607,14 @@ data TcRnMessage where
    1607 1607
                      overloadedrecflds/should_fail/DuplicateExports
    
    1608 1608
                      patsyn/should_compile/T11959
    
    1609 1609
       -}
    
    1610
    -  TcRnDuplicateExport :: GlobalRdrElt -> IE GhcPs -> IE GhcPs -> TcRnMessage
    
    1610
    +  TcRnDuplicateExport :: GlobalRdrElt -> LIE GhcPs -> LIE GhcPs -> TcRnMessage
    
    1611 1611
     
    
    1612 1612
       {-| TcRnDuplicateNamedDefaultExport is a warning (controlled by -Wduplicate-exports)
    
    1613 1613
           that occurs when a named default declaration appears in an export list
    
    1614 1614
           more than once.
    
    1615 1615
     
    
    1616 1616
       -}
    
    1617
    -  TcRnDuplicateNamedDefaultExport :: TyCon -> IE GhcPs -> IE GhcPs -> TcRnMessage
    
    1617
    +  TcRnDuplicateNamedDefaultExport :: TyCon -> LIE GhcPs -> LIE GhcPs -> TcRnMessage
    
    1618 1618
     
    
    1619 1619
       {-| TcRnExportedParentChildMismatch is an error that occurs when an export is
    
    1620 1620
           bundled with a parent that it does not belong to
    

  • compiler/GHC/Tc/Gen/Export.hs
    ... ... @@ -47,7 +47,7 @@ import GHC.Types.Id.Info
    47 47
     import GHC.Types.Name.Reader
    
    48 48
     import GHC.Types.Hint
    
    49 49
     
    
    50
    -import Control.Arrow ( first )
    
    50
    +import Control.Arrow ( first, second )
    
    51 51
     import Control.Monad ( when )
    
    52 52
     import qualified Data.List.NonEmpty as NE
    
    53 53
     import Data.Traversable   ( for )
    
    ... ... @@ -142,7 +142,7 @@ data ExportAccum -- The type of the accumulating parameter of
    142 142
          = ExportAccum {
    
    143 143
              expacc_exp_occs :: ExportOccMap,
    
    144 144
                -- ^ Tracks exported occurrence names
    
    145
    -         expacc_exp_dflts :: NameEnv (ClassDefaults, IE GhcPs),
    
    145
    +         expacc_exp_dflts :: NameEnv (ClassDefaults, LIE GhcPs),
    
    146 146
                -- ^ Tracks exported named default declarations
    
    147 147
              expacc_mods :: UniqMap ModuleName [Name],
    
    148 148
                -- ^ Tracks (re-)exported module names
    
    ... ... @@ -186,7 +186,7 @@ accumExports f xs = do
    186 186
       where f' acc x
    
    187 187
               = fromMaybe (acc, Nothing) <$> attemptM (f acc x)
    
    188 188
     
    
    189
    -type ExportOccMap = OccEnv (Name, IE GhcPs)
    
    189
    +type ExportOccMap = OccEnv (Name, LIE GhcPs)
    
    190 190
             -- Tracks what a particular exported OccName
    
    191 191
             --   in an export list refers to, and which item
    
    192 192
             --   it came from.  It's illegal to export two distinct things
    
    ... ... @@ -414,7 +414,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod
    414 414
                 ; traceRn "efa" (ppr mod $$ ppr all_gres)
    
    415 415
                 ; addUsedGREs ExportDeprecationWarnings all_gres
    
    416 416
     
    
    417
    -            ; occs' <- check_occs occs ie new_gres
    
    417
    +            ; occs' <- check_occs occs (L loc ie) new_gres
    
    418 418
                               -- This check_occs not only finds conflicts
    
    419 419
                               -- between this item and others, but also
    
    420 420
                               -- internally within this item.  That is, if
    
    ... ... @@ -484,7 +484,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod
    484 484
                 ; traceRn "efa" (ppr mod $$ ppr all_gres)
    
    485 485
                 ; addUsedGREs ExportDeprecationWarnings all_gres
    
    486 486
     
    
    487
    -            ; occs' <- check_occs occs ie new_gres
    
    487
    +            ; occs' <- check_occs occs (L loc ie) new_gres
    
    488 488
                               -- This check_occs not only finds conflicts
    
    489 489
                               -- between this item and others, but also
    
    490 490
                               -- internally within this item.  That is, if
    
    ... ... @@ -541,7 +541,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod
    541 541
                        name = greName gre
    
    542 542
     
    
    543 543
                    checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
    
    544
    -               occs' <- check_occs occs ie [gre]
    
    544
    +               occs' <- check_occs occs (L loc ie) [gre]
    
    545 545
                    (export_warn_spans', dont_warn_export', warn_txt_rn)
    
    546 546
                      <- process_warning export_warn_spans
    
    547 547
                                         dont_warn_export
    
    ... ... @@ -579,14 +579,14 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod
    579 579
                            Just cls_dflts -> do
    
    580 580
                              let cls = cd_class cls_dflts
    
    581 581
                              case lookupNameEnv exp_dflts (className cls) of
    
    582
    -                           Just (_, ie') -> do
    
    582
    +                           Just (_, lie') -> do
    
    583 583
                                  addDiagnostic $
    
    584
    -                               TcRnDuplicateNamedDefaultExport (classTyCon cls) ie ie'
    
    584
    +                               TcRnDuplicateNamedDefaultExport (classTyCon cls) (L loc ie) lie'
    
    585 585
                                  return (Nothing, occs, exp_dflts)
    
    586 586
                                Nothing ->
    
    587
    -                            return $ (Nothing, occs, extendNameEnv exp_dflts (className cls) (cls_dflts, ie))
    
    587
    +                            return $ (Nothing, occs, extendNameEnv exp_dflts (className cls) (cls_dflts, L loc ie))
    
    588 588
                        _ -> do
    
    589
    -                    occs' <- check_occs occs ie [gre]
    
    589
    +                    occs' <- check_occs occs (L loc ie) [gre]
    
    590 590
                         return (Just avail, occs', exp_dflts)
    
    591 591
     
    
    592 592
                    checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
    
    ... ... @@ -618,7 +618,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod
    618 618
                        all_names = map greName all_gres
    
    619 619
     
    
    620 620
                    checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
    
    621
    -               occs' <- check_occs occs ie all_gres
    
    621
    +               occs' <- check_occs occs (L loc ie) all_gres
    
    622 622
                    (export_warn_spans', dont_warn_export', warn_txt_rn)
    
    623 623
                      <- process_warning export_warn_spans
    
    624 624
                                         dont_warn_export
    
    ... ... @@ -657,7 +657,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod
    657 657
                        all_names = map greName all_gres
    
    658 658
     
    
    659 659
                    checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
    
    660
    -               occs' <- check_occs occs ie all_gres
    
    660
    +               occs' <- check_occs occs (L loc ie) all_gres
    
    661 661
                    (export_warn_spans', dont_warn_export', warn_txt_rn)
    
    662 662
                      <- process_warning export_warn_spans
    
    663 663
                                         dont_warn_export
    
    ... ... @@ -1044,12 +1044,13 @@ checkPatSynParent parent NoParent nm
    1044 1044
     -- | Insert the given 'GlobalRdrElt's into the 'ExportOccMap', checking that
    
    1045 1045
     -- each of the given 'GlobalRdrElt's does not appear multiple times in
    
    1046 1046
     -- the 'ExportOccMap', as per Note [Exporting duplicate declarations].
    
    1047
    -check_occs :: ExportOccMap -> IE GhcPs -> [GlobalRdrElt] -> RnM ExportOccMap
    
    1048
    -check_occs occs ie gres
    
    1047
    +check_occs :: ExportOccMap -> LIE GhcPs -> [GlobalRdrElt] -> RnM ExportOccMap
    
    1048
    +check_occs occs lie gres
    
    1049 1049
       -- 'gres' are the entities specified by 'ie'
    
    1050 1050
       = do { drf <- xoptM LangExt.DuplicateRecordFields
    
    1051 1051
            ; foldlM (check drf) occs gres }
    
    1052 1052
       where
    
    1053
    +    ie = unLoc lie
    
    1053 1054
     
    
    1054 1055
         -- Check for distinct children exported with the same OccName (an error) or
    
    1055 1056
         -- for duplicate exports of the same child (a warning).
    
    ... ... @@ -1067,20 +1068,21 @@ check_occs occs ie gres
    1067 1068
                 | drf_enabled || not (isFieldOcc child_occ)
    
    1068 1069
                 -> return occs'
    
    1069 1070
                 | otherwise
    
    1070
    -            -> do { let flds = filter (\(_,ie') -> not $ dupFieldExport_ok ie ie')
    
    1071
    +            -> do { let flds = filter (\(_,lie') -> not $ dupFieldExport_ok ie (unLoc lie'))
    
    1071 1072
                                  $ lookupFieldsOccEnv occs (occNameFS child_occ)
    
    1072 1073
                       ; case flds of { [] -> return occs'; clash1:clashes ->
    
    1073
    -               do { addDuplicateFieldExportErr (gre,ie) (clash1 NE.:| clashes)
    
    1074
    +               do { addDuplicateFieldExportErr (gre, unLoc lie)
    
    1075
    +                          (fmap (second unLoc) (clash1 NE.:| clashes))
    
    1074 1076
                       ; return occs } } }
    
    1075 1077
     
    
    1076
    -          Left (child', ie')
    
    1078
    +          Left (child', lie')
    
    1077 1079
                 | child == child' -- Duplicate export of a single Name: a warning.
    
    1078
    -            -> do { warnIf (not (dupExport_ok child ie ie')) (TcRnDuplicateExport gre ie ie')
    
    1080
    +            -> do { warnIf (not (dupExport_ok child ie (unLoc lie'))) (TcRnDuplicateExport gre lie lie')
    
    1079 1081
                       ; return occs }
    
    1080 1082
     
    
    1081 1083
                 | otherwise       -- Same OccName but different Name: an error.
    
    1082 1084
                 ->  do { global_env <- getGlobalRdrEnv
    
    1083
    -                   ; addErr (exportClashErr global_env child' child ie' ie)
    
    1085
    +                   ; addErr (exportClashErr global_env child' child (unLoc lie') (unLoc lie))
    
    1084 1086
                        ; return occs }
    
    1085 1087
           where
    
    1086 1088
             child = greName gre
    
    ... ... @@ -1088,10 +1090,10 @@ check_occs occs ie gres
    1088 1090
     
    
    1089 1091
         -- Try to insert a child into the map, returning Left if there is something
    
    1090 1092
         -- already exported with the same OccName.
    
    1091
    -    try_insert :: ExportOccMap -> GlobalRdrElt -> Either (Name, IE GhcPs) ExportOccMap
    
    1093
    +    try_insert :: ExportOccMap -> GlobalRdrElt -> Either (Name, LIE GhcPs) ExportOccMap
    
    1092 1094
         try_insert occs child
    
    1093 1095
           = case lookupOccEnv occs occ of
    
    1094
    -          Nothing -> Right (extendOccEnv occs occ (greName child, ie))
    
    1096
    +          Nothing -> Right (extendOccEnv occs occ (greName child, lie))
    
    1095 1097
               Just x  -> Left x
    
    1096 1098
           where
    
    1097 1099
             occ = greOccName child
    

  • testsuite/tests/default/T25857.stderr
    1 1
     T25857.hs:4:33: warning: [GHC-31584] [-Wduplicate-exports (in -Wdefault)]
    
    2 2
         The named default declaration for ‘IsString’ is exported by ‘default IsString’ and ‘default IsString’
    
    3
    +  |
    
    4
    +4 |     IsString, default IsString, default IsString
    
    5
    +  |               ^^^^^^^^^^^^^^^^
    
    6
    +  |
    
    7
    +4 |     IsString, default IsString, default IsString
    
    8
    +  |                                 ^^^^^^^^^^^^^^^^
    
    3 9
     

  • testsuite/tests/default/all.T
    ... ... @@ -32,7 +32,7 @@ test('default-fail07', normal, compile_fail, [''])
    32 32
     test('default-fail08', normal, compile_fail, [''])
    
    33 33
     test('T25775', normal, compile_fail, [''])
    
    34 34
     test('T25825', normal, compile, [''])
    
    35
    -test('T25857', normal, compile, [''])
    
    35
    +test('T25857', normal, compile, ['-fdiagnostics-show-caret'])
    
    36 36
     test('T25206', [extra_files(['T25206_helper.hs'])], multimod_compile, ['T25206', ''])
    
    37 37
     test('T25858', normal, compile_and_run, [''])
    
    38 38
     test('T25858v1', [extra_files(['T25858v1_helper.hs'])], multimod_compile_and_run, ['T25858v1', ''])
    

  • testsuite/tests/overloadedrecflds/should_fail/DuplicateExports.stderr
    1
    -
    
    2 1
     DuplicateExports.hs:6:29: error: [GHC-47854] [-Wduplicate-exports (in -Wdefault), Werror=duplicate-exports]
    
    3 2
         ‘foo’ is exported by ‘foo’ and ‘T(foo, bar)’
    
    3
    +  |
    
    4
    +6 | module Export (T(foo, bar), foo, S(bar)) where
    
    5
    +  |                ^^^^^^^^^^^
    
    6
    +  |
    
    7
    +6 | module Export (T(foo, bar), foo, S(bar)) where
    
    8
    +  |                             ^^^
    
    9
    +

  • testsuite/tests/overloadedrecflds/should_fail/all.T
    ... ... @@ -35,7 +35,7 @@ test('T14953', [extra_files(['T14953_A.hs', 'T14953_B.hs'])],
    35 35
          multimod_compile_fail, ['T14953', ''])
    
    36 36
     test('T26480', extra_files(['T26480_aux1.hs', 'T26480_aux2.hs']), multimod_compile_fail, ['T26480', '-v0'])
    
    37 37
     test('T26480b', normal, compile_fail, [''])
    
    38
    -test('DuplicateExports', normal, compile_fail, [''])
    
    38
    +test('DuplicateExports', normal, compile_fail, ['-fdiagnostics-show-caret'])
    
    39 39
     test('T17420', [extra_files(['T17420A.hs'])], multimod_compile_fail,
    
    40 40
          ['T17420', ''])
    
    41 41
     test('T17469', [extra_files(['T17469A.hs'])], multimod_compile_fail,
    

  • testsuite/tests/rename/should_fail/T7164.stderr
    1
    -
    
    2
    -T7164.hs:8:1: [GHC-29916]
    
    1
    +T7164.hs:8:1: error: [GHC-29916]
    
    3 2
         Multiple declarations of ‘derp’
    
    4 3
         Declared at: T7164.hs:5:5
    
    5 4
                      T7164.hs:8:1
    
    5
    +  |
    
    6
    +5 |     derp :: m a
    
    7
    +  |     ^^^^^^^^^^^
    
    8
    +  |
    
    9
    +8 | derp = 123
    
    10
    +  | ^^^^
    
    11
    +

  • testsuite/tests/rename/should_fail/all.T
    ... ... @@ -91,7 +91,7 @@ test('T6148a', normal, compile_fail, [''])
    91 91
     test('T6148b', normal, compile_fail, [''])
    
    92 92
     test('T6148c', normal, compile_fail, [''])
    
    93 93
     test('T6148d', normal, compile_fail, [''])
    
    94
    -test('T7164', normal, compile_fail, [''])
    
    94
    +test('T7164', normal, compile_fail, ['-fdiagnostics-show-caret'])
    
    95 95
     test('T7338', normal, compile_fail, [''])
    
    96 96
     test('T7338a', normal, compile_fail, [''])
    
    97 97
     test('T7454', normal, compile, [''])