diff options
author | Shayne Fletcher <shayne@shaynefletcher.org> | 2021-04-24 16:59:26 -0400 |
---|---|---|
committer | Shayne Fletcher <shayne@shaynefletcher.org> | 2021-04-26 18:52:13 -0400 |
commit | 76f82c0eb0212a1d6d2712996b4f19984aec80be (patch) | |
tree | d86f70f6b432ddbeadc6d427d8c366718468be33 | |
parent | 7bc7eea3897dcb8a87fdb0921f451b9bc77309f6 (diff) | |
download | haskell-wip/T19720.tar.gz |
Change representation of field selector occurenceswip/T19720
48 files changed, 194 insertions, 457 deletions
diff --git a/compiler/GHC/Hs/Pat.hs b/compiler/GHC/Hs/Pat.hs index 577321ea0a..5048cc019b 100644 --- a/compiler/GHC/Hs/Pat.hs +++ b/compiler/GHC/Hs/Pat.hs @@ -223,7 +223,7 @@ hsRecUpdFieldRdr :: HsRecUpdField (GhcPass p) -> Located RdrName hsRecUpdFieldRdr = fmap rdrNameAmbiguousFieldOcc . hsRecFieldLbl hsRecUpdFieldId :: HsRecField' (AmbiguousFieldOcc GhcTc) arg -> Located Id -hsRecUpdFieldId = fmap extFieldOcc . hsRecUpdFieldOcc +hsRecUpdFieldId = fmap foExt . hsRecUpdFieldOcc hsRecUpdFieldOcc :: HsRecField' (AmbiguousFieldOcc GhcTc) arg -> LFieldOcc GhcTc hsRecUpdFieldOcc = fmap unambiguousFieldOcc . hsRecFieldLbl diff --git a/compiler/GHC/Hs/Utils.hs b/compiler/GHC/Hs/Utils.hs index bf37398347..eac1235cdc 100644 --- a/compiler/GHC/Hs/Utils.hs +++ b/compiler/GHC/Hs/Utils.hs @@ -1341,7 +1341,7 @@ hsTyClForeignBinders tycl_decls foreign_decls foldMap (foldMap hsLInstDeclBinders . group_instds) tycl_decls) where getSelectorNames :: ([LocatedA Name], [LFieldOcc GhcRn]) -> [Name] - getSelectorNames (ns, fs) = map unLoc ns ++ map (extFieldOcc . unLoc) fs + getSelectorNames (ns, fs) = map unLoc ns ++ map (foExt . unLoc) fs ------------------- hsLTyClDeclBinders :: IsPass p @@ -1490,7 +1490,7 @@ hsConDeclsBinders cons where fld_names = remSeen (concatMap (cd_fld_names . unLoc) (unLoc flds)) remSeen' = foldr (.) remSeen - [deleteBy ((==) `on` unLoc . rdrNameFieldOcc . unLoc) v + [deleteBy ((==) `on` unLoc . foLabel . unLoc) v | v <- fld_names] {- diff --git a/compiler/GHC/HsToCore/Coverage.hs b/compiler/GHC/HsToCore/Coverage.hs index 8a6bb4e160..17521fd6b7 100644 --- a/compiler/GHC/HsToCore/Coverage.hs +++ b/compiler/GHC/HsToCore/Coverage.hs @@ -518,8 +518,7 @@ addBinTickLHsExpr boxLabel (L pos e0) addTickHsExpr :: HsExpr GhcTc -> TM (HsExpr GhcTc) addTickHsExpr e@(HsVar _ (L _ id)) = do freeVar id; return e addTickHsExpr e@(HsUnboundVar {}) = return e -addTickHsExpr e@(HsRecFld _ (Ambiguous id _)) = do freeVar id; return e -addTickHsExpr e@(HsRecFld _ (Unambiguous id _)) = do freeVar id; return e +addTickHsExpr e@(HsRecFld _ (FieldOcc id _)) = do freeVar id; return e addTickHsExpr e@(HsConLikeOut {}) = return e -- We used to do a freeVar on a pat-syn builder, but actually diff --git a/compiler/GHC/HsToCore/Docs.hs b/compiler/GHC/HsToCore/Docs.hs index 0dd6267db6..df2e334213 100644 --- a/compiler/GHC/HsToCore/Docs.hs +++ b/compiler/GHC/HsToCore/Docs.hs @@ -209,7 +209,7 @@ subordinates instMap decl = case decl of , maybeToList $ fmap unLoc $ con_doc c , conArgDocs c) | c <- cons, cname <- getConNames c ] - fields = [ (extFieldOcc n, maybeToList $ fmap unLoc doc, IM.empty) + fields = [ (foExt n, maybeToList $ fmap unLoc doc, IM.empty) | Just flds <- map getRecConArgs_maybe cons , (L _ (ConDeclField _ ns _ doc)) <- (unLoc flds) , (L _ n) <- ns ] diff --git a/compiler/GHC/HsToCore/Expr.hs b/compiler/GHC/HsToCore/Expr.hs index 37d72fa213..c6391d5e8e 100644 --- a/compiler/GHC/HsToCore/Expr.hs +++ b/compiler/GHC/HsToCore/Expr.hs @@ -266,8 +266,7 @@ dsLExprNoLP (L loc e) dsExpr :: HsExpr GhcTc -> DsM CoreExpr dsExpr (HsVar _ (L _ id)) = dsHsVar id -dsExpr (HsRecFld _ (Unambiguous id _)) = dsHsVar id -dsExpr (HsRecFld _ (Ambiguous id _)) = dsHsVar id +dsExpr (HsRecFld _ (FieldOcc id _)) = dsHsVar id dsExpr (HsUnboundVar (HER ref _ _) _) = dsEvTerm =<< readMutVar ref -- See Note [Holes] in GHC.Tc.Types.Constraint diff --git a/compiler/GHC/HsToCore/Quote.hs b/compiler/GHC/HsToCore/Quote.hs index e13f0ceb50..15b9f508f1 100644 --- a/compiler/GHC/HsToCore/Quote.hs +++ b/compiler/GHC/HsToCore/Quote.hs @@ -285,7 +285,7 @@ repTopDs group@(HsGroup { hs_valds = valds , hs_docs = docs }) = do { let { bndrs = hsScopedTvBinders valds ++ hsGroupBinders group - ++ map extFieldOcc (hsPatSynSelectors valds) + ++ map foExt (hsPatSynSelectors valds) ; instds = tyclds >>= group_instds } ; ss <- mkGenSyms bndrs ; @@ -1487,9 +1487,7 @@ repE (HsVar _ (L _ x)) = repE (HsIPVar _ n) = rep_implicit_param_name n >>= repImplicitParamVar repE (HsOverLabel _ s) = repOverLabel s -repE e@(HsRecFld _ f) = case f of - Unambiguous x _ -> repE (HsVar noExtField (noLocA x)) - Ambiguous{} -> notHandled "Ambiguous record selectors" (ppr e) +repE (HsRecFld _ (FieldOcc x _)) = repE (HsVar noExtField (noLocA x)) -- Remember, we're desugaring renamer output here, so -- HsOverlit can definitely occur @@ -1930,7 +1928,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn mkGenArgSyms (InfixCon arg1 arg2) = mkGenSyms [unLoc arg1, unLoc arg2] mkGenArgSyms (RecCon fields) = do { let pats = map (unLoc . recordPatSynPatVar) fields - sels = map (extFieldOcc . recordPatSynField) fields + sels = map (foExt . recordPatSynField) fields ; ss <- mkGenSyms sels ; return $ replaceNames (zip sels pats) ss } @@ -1960,7 +1958,7 @@ repPatSynArgs (InfixCon arg1 arg2) ; arg2' <- lookupLOcc arg2 ; repInfixPatSynArgs arg1' arg2' } repPatSynArgs (RecCon fields) - = do { sels' <- repList nameTyConName (lookupOcc . extFieldOcc) sels + = do { sels' <- repList nameTyConName (lookupOcc . foExt) sels ; repRecordPatSynArgs sels' } where sels = map recordPatSynField fields @@ -2707,7 +2705,7 @@ repRecConArgs ips = do rep_ip (L _ ip) = mapM (rep_one_ip (cd_fld_type ip)) (cd_fld_names ip) rep_one_ip :: LBangType GhcRn -> LFieldOcc GhcRn -> MetaM (Core (M TH.VarBangType)) - rep_one_ip t n = do { MkC v <- lookupOcc (extFieldOcc $ unLoc n) + rep_one_ip t n = do { MkC v <- lookupOcc (foExt $ unLoc n) ; MkC ty <- repBangTy t ; rep2 varBangTypeName [v,ty] } diff --git a/compiler/GHC/Iface/Ext/Ast.hs b/compiler/GHC/Iface/Ext/Ast.hs index 5a787f5b94..984b0fa4ff 100644 --- a/compiler/GHC/Iface/Ext/Ast.hs +++ b/compiler/GHC/Iface/Ext/Ast.hs @@ -907,7 +907,7 @@ instance HiePass p => ToHie (Located (PatSynBind (GhcPass p) (GhcPass p))) where (InfixCon a b) -> combineScopes (mkLScopeN a) (mkLScopeN b) (RecCon r) -> foldr go NoScope r go (RecordPatSynField a b) c = combineScopes c - $ combineScopes (mkLScopeN (rdrNameFieldOcc a)) (mkLScopeN b) + $ combineScopes (mkLScopeN (foLabel a)) (mkLScopeN b) detSpan = case detScope of LocalScope a -> Just a _ -> Nothing diff --git a/compiler/GHC/Parser/Annotation.hs b/compiler/GHC/Parser/Annotation.hs index f234c7c789..6f29fa8f40 100644 --- a/compiler/GHC/Parser/Annotation.hs +++ b/compiler/GHC/Parser/Annotation.hs @@ -1226,6 +1226,11 @@ instance (Outputable a, Outputable e) => Outputable (GenLocated (SrcSpanAnn' a) e) where ppr = pprLocated +instance (Outputable a, OutputableBndr e) + => OutputableBndr (GenLocated (SrcSpanAnn' a) e) where + pprInfixOcc = pprInfixOcc . unLoc + pprPrefixOcc = pprPrefixOcc . unLoc + instance Outputable AnnListItem where ppr (AnnListItem ts) = text "AnnListItem" <+> ppr ts diff --git a/compiler/GHC/Rename/Bind.hs b/compiler/GHC/Rename/Bind.hs index a37f88bc83..bb2774f43a 100644 --- a/compiler/GHC/Rename/Bind.hs +++ b/compiler/GHC/Rename/Bind.hs @@ -694,7 +694,7 @@ rnPatSynBind sig_fn bind@(PSB { psb_id = L l name ; return ( (pat', InfixCon name1 name2) , mkFVs (map unLoc [name1, name2])) } RecCon vars -> - do { checkDupRdrNames (map (rdrNameFieldOcc . recordPatSynField) vars) + do { checkDupRdrNames (map (foLabel . recordPatSynField) vars) ; fls <- lookupConstructorFields name ; let fld_env = mkFsEnv [ (flLabel fl, fl) | fl <- fls ] ; let rnRecordPatSynField @@ -730,7 +730,7 @@ rnPatSynBind sig_fn bind@(PSB { psb_id = L l name , psb_ext = fvs' } selector_names = case details' of RecCon names -> - map (extFieldOcc . recordPatSynField) names + map (foExt . recordPatSynField) names _ -> [] ; fvs' `seq` -- See Note [Free-variable space leak] diff --git a/compiler/GHC/Rename/Expr.hs b/compiler/GHC/Rename/Expr.hs index bbf52be2f8..f6ff657f50 100644 --- a/compiler/GHC/Rename/Expr.hs +++ b/compiler/GHC/Rename/Expr.hs @@ -41,6 +41,7 @@ import GHC.Rename.Utils ( HsDocContext(..), bindLocalNamesFV, checkDupNames , bindLocalNames , mapMaybeFvRn, mapFvRn , warnUnusedLocalBinds, typeAppErr + , ambiguousFieldOccErr , checkUnusedRecordWildcard ) import GHC.Rename.Unbound ( reportUnboundName ) import GHC.Rename.Splice ( rnBracket, rnSpliceExpr, checkThLocalName ) @@ -228,10 +229,13 @@ rnExpr (HsVar _ (L l v)) -> finishHsVar (L (na2la l) name) ; Just (UnambiguousGre (FieldGreName fl)) -> let sel_name = flSelector fl in - return ( HsRecFld noExtField (Unambiguous sel_name (L l v) ), unitFV sel_name) ; - Just AmbiguousFields -> - return ( HsRecFld noExtField (Ambiguous noExtField (L l v) ), emptyFVs) } } - + return ( HsRecFld noExtField (FieldOcc sel_name (L l v) ), unitFV sel_name) ; + Just AmbiguousFields -> do { + addErr $ ambiguousFieldOccErr v + ; return (HsUnboundVar noExtField (rdrNameOcc v), emptyFVs) + } + } + } rnExpr (HsIPVar x v) = return (HsIPVar x v, emptyFVs) diff --git a/compiler/GHC/Rename/Fixity.hs b/compiler/GHC/Rename/Fixity.hs index e45f3a5cdb..39462baf36 100644 --- a/compiler/GHC/Rename/Fixity.hs +++ b/compiler/GHC/Rename/Fixity.hs @@ -30,15 +30,11 @@ import GHC.Types.SourceText import GHC.Types.SrcLoc import GHC.Utils.Outputable -import GHC.Utils.Panic import GHC.Data.Maybe import GHC.Rename.Unbound -import Data.List (groupBy) -import Data.Function ( on ) - {- ********************************************************* * * @@ -184,39 +180,10 @@ lookupFixityRn_help' name occ lookupTyFixityRn :: LocatedN Name -> RnM Fixity lookupTyFixityRn = lookupFixityRn . unLoc --- | Look up the fixity of a (possibly ambiguous) occurrence of a record field --- selector. We use 'lookupFixityRn'' so that we can specify the 'OccName' as --- the field label, which might be different to the 'OccName' of the selector --- 'Name' if @DuplicateRecordFields@ is in use (#1173). If there are --- multiple possible selectors with different fixities, generate an error. -lookupFieldFixityRn :: AmbiguousFieldOcc GhcRn -> RnM Fixity -lookupFieldFixityRn (Unambiguous n lrdr) +-- | Look up the fixity of an occurrence of a record field selector. +-- We use 'lookupFixityRn'' so that we can specify the 'OccName' as +-- the field label, which might be different to the 'OccName' of the +-- selector 'Name' if @DuplicateRecordFields@ is in use (#1173). +lookupFieldFixityRn :: FieldOcc GhcRn -> RnM Fixity +lookupFieldFixityRn (FieldOcc n lrdr) = lookupFixityRn' n (rdrNameOcc (unLoc lrdr)) -lookupFieldFixityRn (Ambiguous _ lrdr) = get_ambiguous_fixity (unLoc lrdr) - where - get_ambiguous_fixity :: RdrName -> RnM Fixity - get_ambiguous_fixity rdr_name = do - traceRn "get_ambiguous_fixity" (ppr rdr_name) - rdr_env <- getGlobalRdrEnv - let elts = lookupGRE_RdrName rdr_name rdr_env - - fixities <- groupBy ((==) `on` snd) . zip elts - <$> mapM lookup_gre_fixity elts - - case fixities of - -- There should always be at least one fixity. - -- Something's very wrong if there are no fixity candidates, so panic - [] -> panic "get_ambiguous_fixity: no candidates for a given RdrName" - [ (_, fix):_ ] -> return fix - ambigs -> addErr (ambiguous_fixity_err rdr_name ambigs) - >> return (Fixity NoSourceText minPrecedence InfixL) - - lookup_gre_fixity gre = lookupFixityRn' (greMangledName gre) (greOccName gre) - - ambiguous_fixity_err rn ambigs - = vcat [ text "Ambiguous fixity for record field" <+> quotes (ppr rn) - , hang (text "Conflicts: ") 2 . vcat . - map format_ambig $ concat ambigs ] - - format_ambig (elt, fix) = hang (ppr fix) - 2 (pprNameProvenance elt) diff --git a/compiler/GHC/Rename/HsType.hs b/compiler/GHC/Rename/HsType.hs index d11c4c9634..23de5404e9 100644 --- a/compiler/GHC/Rename/HsType.hs +++ b/compiler/GHC/Rename/HsType.hs @@ -1395,11 +1395,10 @@ mkOpAppRn e1 op fix e2 -- Default case, no rearrangment ---------------------------- -- | Name of an operator in an operator application or section -data OpName = NormalOp Name -- ^ A normal identifier - | NegateOp -- ^ Prefix negation - | UnboundOp OccName -- ^ An unbound indentifier - | RecFldOp (AmbiguousFieldOcc GhcRn) - -- ^ A (possibly ambiguous) record field occurrence +data OpName = NormalOp Name -- ^ A normal identifier + | NegateOp -- ^ Prefix negation + | UnboundOp OccName -- ^ An unbound indentifier + | RecFldOp (FieldOcc GhcRn) -- ^ A record field occurrence instance Outputable OpName where ppr (NormalOp n) = ppr n @@ -1576,8 +1575,7 @@ checkSectionPrec direction section op arg (arg_op, arg_fix) section) -- | Look up the fixity for an operator name. Be careful to use --- 'lookupFieldFixityRn' for (possibly ambiguous) record fields --- (see #13132). +-- 'lookupFieldFixityRn' for record fields (see #13132). lookupFixityOp :: OpName -> RnM Fixity lookupFixityOp (NormalOp n) = lookupFixityRn n lookupFixityOp NegateOp = lookupFixityRn negateName diff --git a/compiler/GHC/Rename/Module.hs b/compiler/GHC/Rename/Module.hs index 8de0c4a34f..a3f51d878e 100644 --- a/compiler/GHC/Rename/Module.hs +++ b/compiler/GHC/Rename/Module.hs @@ -2428,7 +2428,7 @@ extendPatSynEnv dup_fields_ok has_sel val_decls local_fix_env thing = do { , psb_args = RecCon as }))) <- bind = do bnd_name <- newTopSrcBinder (L (l2l bind_loc) n) - let field_occs = map ((\ f -> L (getLocA (rdrNameFieldOcc f)) f) . recordPatSynField) as + let field_occs = map ((\ f -> L (getLocA (foLabel f)) f) . recordPatSynField) as flds <- mapM (newRecordSelector dup_fields_ok has_sel [bnd_name]) field_occs return ((bnd_name, flds): names) | L bind_loc (PatSynBind _ (PSB { psb_id = L _ n})) <- bind diff --git a/compiler/GHC/Rename/Pat.hs b/compiler/GHC/Rename/Pat.hs index 1c847dfb97..e89861edf9 100644 --- a/compiler/GHC/Rename/Pat.hs +++ b/compiler/GHC/Rename/Pat.hs @@ -806,7 +806,7 @@ getFieldIds flds = map (unLoc . hsRecFieldSel . unLoc) flds getFieldLbls :: forall p arg . UnXRec p => [LHsRecField p arg] -> [RdrName] getFieldLbls flds - = map (unLoc . rdrNameFieldOcc . unLoc . hsRecFieldLbl . unXRec @p) flds + = map (unXRec @p. foLabel . unLoc . hsRecFieldLbl . unXRec @p) flds getFieldUpdLbls :: [LHsRecUpdField GhcPs] -> [RdrName] getFieldUpdLbls flds = map (rdrNameAmbiguousFieldOcc . unLoc . hsRecFieldLbl . unLoc) flds diff --git a/compiler/GHC/Rename/Utils.hs b/compiler/GHC/Rename/Utils.hs index e5d27fa234..75952fb7df 100644 --- a/compiler/GHC/Rename/Utils.hs +++ b/compiler/GHC/Rename/Utils.hs @@ -18,6 +18,7 @@ module GHC.Rename.Utils ( checkUnusedRecordWildcard, mkFieldEnv, unknownSubordinateErr, badQualBndrErr, typeAppErr, + ambiguousFieldOccErr, HsDocContext(..), pprHsDocContext, inHsDocContext, withHsDocContext, @@ -605,6 +606,10 @@ badQualBndrErr :: RdrName -> SDoc badQualBndrErr rdr_name = text "Qualified name in binding position:" <+> ppr rdr_name +ambiguousFieldOccErr :: RdrName -> SDoc +ambiguousFieldOccErr rdr_name + = text "Ambiguous field selector occurence:" <+> ppr rdr_name + typeAppErr :: String -> LHsType GhcPs -> SDoc typeAppErr what (L _ k) = hang (text "Illegal visible" <+> text what <+> text "application" diff --git a/compiler/GHC/Tc/Gen/App.hs b/compiler/GHC/Tc/Gen/App.hs index 4f4f53f1cf..e78316a9c2 100644 --- a/compiler/GHC/Tc/Gen/App.hs +++ b/compiler/GHC/Tc/Gen/App.hs @@ -140,7 +140,7 @@ tcInferSigma inst (L loc rn_expr) = addExprCtxt rn_expr $ setSrcSpanA loc $ do { do_ql <- wantQuickLook rn_fun - ; (_tc_fun, fun_sigma) <- tcInferAppHead fun rn_args Nothing + ; (_tc_fun, fun_sigma) <- tcInferAppHead fun rn_args ; (_delta, inst_args, app_res_sigma) <- tcInstFun do_ql inst fun fun_sigma rn_args ; _tc_args <- tcValArgs do_ql inst_args ; return app_res_sigma } @@ -313,7 +313,6 @@ tcApp :: HsExpr GhcRn -> ExpRhoType -> TcM (HsExpr GhcTc) tcApp rn_expr exp_res_ty | (fun@(rn_fun, fun_ctxt), rn_args) <- splitHsApps rn_expr = do { (tc_fun, fun_sigma) <- tcInferAppHead fun rn_args - (checkingExpType_maybe exp_res_ty) -- Instantiate ; do_ql <- wantQuickLook rn_fun @@ -854,7 +853,7 @@ quickLookArg1 :: Bool -> Delta -> LHsExpr GhcRn -> TcSigmaType -> TcM (Delta, EValArg 'TcpInst) quickLookArg1 guarded delta larg@(L _ arg) arg_ty = do { let (fun@(rn_fun, fun_ctxt), rn_args) = splitHsApps arg - ; mb_fun_ty <- tcInferAppHead_maybe rn_fun rn_args (Just arg_ty) + ; mb_fun_ty <- tcInferAppHead_maybe rn_fun rn_args ; traceTc "quickLookArg 1" $ vcat [ text "arg:" <+> ppr arg , text "head:" <+> ppr rn_fun <+> dcolon <+> ppr mb_fun_ty diff --git a/compiler/GHC/Tc/Gen/Expr.hs b/compiler/GHC/Tc/Gen/Expr.hs index ecd07c6059..fd6568e186 100644 --- a/compiler/GHC/Tc/Gen/Expr.hs +++ b/compiler/GHC/Tc/Gen/Expr.hs @@ -23,7 +23,6 @@ module GHC.Tc.Gen.Expr tcPolyExpr, tcExpr, tcSyntaxOp, tcSyntaxOpGen, SyntaxOpType(..), synKnownType, tcCheckId, - addAmbiguousNameErr, getFixedTyVars ) where #include "HsVersions.h" @@ -978,7 +977,7 @@ tcSyntaxOpGen :: CtOrigin -> ([TcSigmaType] -> [Mult] -> TcM a) -> TcM (a, SyntaxExprTc) tcSyntaxOpGen orig (SyntaxExprRn op) arg_tys res_ty thing_inside - = do { (expr, sigma) <- tcInferAppHead (op, VACall op 0 noSrcSpan) [] Nothing + = do { (expr, sigma) <- tcInferAppHead (op, VACall op 0 noSrcSpan) [] -- Ugh!! But all this code is scheduled for demolition anyway ; traceTc "tcSyntaxOpGen" (ppr op $$ ppr expr $$ ppr sigma) ; (result, expr_wrap, arg_wraps, res_wrap) @@ -1375,7 +1374,7 @@ tcRecordUpd con_like arg_tys rbinds = fmap catMaybes $ mapM do_bind rbinds return (Just (L l (fld { hsRecFieldLbl = L loc (Unambiguous - (extFieldOcc (unLoc f')) + (foExt (unLoc f')) (L (noAnnSrcSpan loc) lbl)) , hsRecFieldArg = rhs' }))) } diff --git a/compiler/GHC/Tc/Gen/Head.hs b/compiler/GHC/Tc/Gen/Head.hs index feb984fc26..83803c0413 100644 --- a/compiler/GHC/Tc/Gen/Head.hs +++ b/compiler/GHC/Tc/Gen/Head.hs @@ -24,7 +24,7 @@ module GHC.Tc.Gen.Head , tcInferAppHead, tcInferAppHead_maybe , tcInferId, tcCheckId - , obviousSig, addAmbiguousNameErr + , obviousSig , tyConOf, tyConOfET, lookupParents, fieldNotInType , notSelector, nonBidirectionalErr @@ -41,11 +41,10 @@ import GHC.Tc.Utils.Monad import GHC.Tc.Utils.Unify import GHC.Types.Basic import GHC.Tc.Utils.Instantiate -import GHC.Tc.Instance.Family ( tcGetFamInstEnvs, tcLookupDataFamInst ) +import GHC.Tc.Instance.Family ( tcLookupDataFamInst ) import GHC.Core.FamInstEnv ( FamInstEnvs ) import GHC.Core.UsageEnv ( unitUE ) -import GHC.Rename.Env ( addUsedGRE ) -import GHC.Rename.Utils ( addNameClashErrRn, unknownSubordinateErr ) +import GHC.Rename.Utils ( unknownSubordinateErr ) import GHC.Tc.Solver ( InferMode(..), simplifyInfer ) import GHC.Tc.Utils.Env import GHC.Tc.Utils.Zonk ( hsLitType ) @@ -75,7 +74,6 @@ import GHC.Utils.Panic import Control.Monad import Data.Function -import qualified Data.List.NonEmpty as NE #include "HsVersions.h" @@ -373,8 +371,7 @@ It's easy to achieve this: `splitHsApps` unwraps `HsExpanded`. ********************************************************************* -} tcInferAppHead :: (HsExpr GhcRn, AppCtxt) - -> [HsExprArg 'TcpRn] -> Maybe TcRhoType - -- These two args are solely for tcInferRecSelId + -> [HsExprArg 'TcpRn] -> TcM (HsExpr GhcTc, TcSigmaType) -- Infer type of the head of an application -- i.e. the 'f' in (f e1 ... en) @@ -385,10 +382,10 @@ tcInferAppHead :: (HsExpr GhcRn, AppCtxt) -- * An expression with a type signature (e :: ty) -- See Note [Application chains and heads] in GHC.Tc.Gen.App -- --- Why do we need the arguments to infer the type of the head of --- the application? For two reasons: --- * (Legitimate) The first arg has the source location of the head --- * (Disgusting) Needed for record disambiguation; see tcInferRecSelId +-- Why do we need the arguments to infer the type of the head of the +-- application? Simply to inform add_head_ctxt about whether or not +-- to put push a new "In the expression..." context. (We don't push a +-- new one if there are no arguments, because we already have.) -- -- Note that [] and (,,) are both HsVar: -- see Note [Empty lists] and [ExplicitTuple] in GHC.Hs.Expr @@ -397,24 +394,23 @@ tcInferAppHead :: (HsExpr GhcRn, AppCtxt) -- cases are dealt with by splitHsApps. -- -- See Note [tcApp: typechecking applications] in GHC.Tc.Gen.App -tcInferAppHead (fun,ctxt) args mb_res_ty +tcInferAppHead (fun,ctxt) args = setSrcSpan (appCtxtLoc ctxt) $ - do { mb_tc_fun <- tcInferAppHead_maybe fun args mb_res_ty + do { mb_tc_fun <- tcInferAppHead_maybe fun args ; case mb_tc_fun of Just (fun', fun_sigma) -> return (fun', fun_sigma) Nothing -> add_head_ctxt fun args $ tcInfer (tcExpr fun) } tcInferAppHead_maybe :: HsExpr GhcRn - -> [HsExprArg 'TcpRn] -> Maybe TcRhoType - -- These two args are solely for tcInferRecSelId + -> [HsExprArg 'TcpRn] -> TcM (Maybe (HsExpr GhcTc, TcSigmaType)) -- See Note [Application chains and heads] in GHC.Tc.Gen.App -- Returns Nothing for a complicated head -tcInferAppHead_maybe fun args mb_res_ty +tcInferAppHead_maybe fun args = case fun of HsVar _ (L _ nm) -> Just <$> tcInferId nm - HsRecFld _ f -> Just <$> tcInferRecSelId f args mb_res_ty + HsRecFld _ f -> Just <$> tcInferRecSelId f ExprWithTySig _ e hs_ty -> add_head_ctxt fun args $ Just <$> tcExprWithSig e hs_ty HsOverLit _ lit -> Just <$> tcInferOverLit lit @@ -434,217 +430,39 @@ add_head_ctxt fun args thing_inside * * ********************************************************************* -} -{- -Note [Deprecating ambiguous fields] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In the future, the -XDuplicateRecordFields extension will no longer support -disambiguating record fields during type-checking (as described in Note -[Disambiguating record fields]). For now, the -Wambiguous-fields option will -emit a warning whenever an ambiguous field is resolved using type information. -In a subsequent GHC release, this functionality will be removed and the warning -will turn into an ambiguity error in the renamer. - -For background information, see GHC proposal #366 -(https://github.com/ghc-proposals/ghc-proposals/pull/366). - - -Note [Disambiguating record fields] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -NB. The following is going to be removed: see -Note [Deprecating ambiguous fields]. - -When the -XDuplicateRecordFields extension is used, and the renamer -encounters a record selector or update that it cannot immediately -disambiguate (because it involves fields that belong to multiple -datatypes), it will defer resolution of the ambiguity to the -typechecker. In this case, the `Ambiguous` constructor of -`AmbiguousFieldOcc` is used. - -Consider the following definitions: - - data S = MkS { foo :: Int } - data T = MkT { foo :: Int, bar :: Int } - data U = MkU { bar :: Int, baz :: Int } - -When the renamer sees `foo` as a selector or an update, it will not -know which parent datatype is in use. - -For selectors, there are two possible ways to disambiguate: - -1. Check if the pushed-in type is a function whose domain is a - datatype, for example: - - f s = (foo :: S -> Int) s - - g :: T -> Int - g = foo - - This is checked by `tcCheckRecSelId` when checking `HsRecFld foo`. - -2. Check if the selector is applied to an argument that has a type - signature, for example: - - h = foo (s :: S) - - This is checked by `tcInferRecSelId`. - - -Updates are slightly more complex. The `disambiguateRecordBinds` -function tries to determine the parent datatype in three ways: - -1. Check for types that have all the fields being updated. For example: - - f x = x { foo = 3, bar = 2 } - - Here `f` must be updating `T` because neither `S` nor `U` have - both fields. This may also discover that no possible type exists. - For example the following will be rejected: - - f' x = x { foo = 3, baz = 3 } - -2. Use the type being pushed in, if it is already a TyConApp. The - following are valid updates to `T`: - - g :: T -> T - g x = x { foo = 3 } - - g' x = x { foo = 3 } :: T - -3. Use the type signature of the record expression, if it exists and - is a TyConApp. Thus this is valid update to `T`: - - h x = (x :: T) { foo = 3 } - - -Note that we do not look up the types of variables being updated, and -no constraint-solving is performed, so for example the following will -be rejected as ambiguous: - - let bad (s :: S) = foo s - - let r :: T - r = blah - in r { foo = 3 } - - \r. (r { foo = 3 }, r :: T ) - -We could add further tests, of a more heuristic nature. For example, -rather than looking for an explicit signature, we could try to infer -the type of the argument to a selector or the record expression being -updated, in case we are lucky enough to get a TyConApp straight -away. However, it might be hard for programmers to predict whether a -particular update is sufficiently obvious for the signature to be -omitted. Moreover, this might change the behaviour of typechecker in -non-obvious ways. - -See also Note [HsRecField and HsRecUpdField] in GHC.Hs.Pat. --} - -tcInferRecSelId :: AmbiguousFieldOcc GhcRn - -> [HsExprArg 'TcpRn] -> Maybe TcRhoType +tcInferRecSelId :: FieldOcc GhcRn -> TcM (HsExpr GhcTc, TcSigmaType) -tcInferRecSelId (Unambiguous sel_name lbl) _args _mb_res_ty - = do { sel_id <- tc_rec_sel_id lbl sel_name - ; let expr = HsRecFld noExtField (Unambiguous sel_id lbl) - ; return (expr, idType sel_id) } - -tcInferRecSelId (Ambiguous _ lbl) args mb_res_ty - = do { sel_name <- tcInferAmbiguousRecSelId lbl args mb_res_ty - ; sel_id <- tc_rec_sel_id lbl sel_name - ; let expr = HsRecFld noExtField (Ambiguous sel_id lbl) - ; return (expr, idType sel_id) } +tcInferRecSelId (FieldOcc sel_name lbl) + = do { sel_id <- tc_rec_sel_id sel_name + ; let expr = HsRecFld noExtField (FieldOcc sel_id lbl) + ; return (expr, idType sel_id) + } + where + occ :: OccName + occ = rdrNameOcc (unLoc lbl) + + tc_rec_sel_id :: Name -> TcM TcId + -- Like tc_infer_id, but returns an Id not a HsExpr, + -- so we can wrap it back up into a HsRecFld + tc_rec_sel_id sel_name + = do { thing <- tcLookup sel_name + ; case thing of + ATcId { tct_id = id } + -> do { check_naughty occ id + ; check_local_id id + ; return id } + + AGlobal (AnId id) + -> do { check_naughty occ id + ; return id } + -- A global cannot possibly be ill-staged + -- nor does it need the 'lifting' treatment + -- hence no checkTh stuff here + + _ -> failWithTc $ + ppr thing <+> text "used where a value identifier was expected" } ------------------------ -tc_rec_sel_id :: LocatedN RdrName -> Name -> TcM TcId --- Like tc_infer_id, but returns an Id not a HsExpr, --- so we can wrap it back up into a HsRecFld -tc_rec_sel_id lbl sel_name - = do { thing <- tcLookup sel_name - ; case thing of - ATcId { tct_id = id } - -> do { check_naughty occ id - ; check_local_id id - ; return id } - - AGlobal (AnId id) - -> do { check_naughty occ id - ; return id } - -- A global cannot possibly be ill-staged - -- nor does it need the 'lifting' treatment - -- hence no checkTh stuff here - - _ -> failWithTc $ - ppr thing <+> text "used where a value identifier was expected" } - where - occ = rdrNameOcc (unLoc lbl) - ------------------------- -tcInferAmbiguousRecSelId :: LocatedN RdrName - -> [HsExprArg 'TcpRn] -> Maybe TcRhoType - -> TcM Name --- Disgusting special case for ambiguous record selectors --- Given a RdrName that refers to multiple record fields, and the type --- of its argument, try to determine the name of the selector that is --- meant. --- See Note [Disambiguating record fields] -tcInferAmbiguousRecSelId lbl args mb_res_ty - | arg1 : _ <- dropWhile (not . isVisibleArg) args -- A value arg is first - , EValArg { eva_arg = ValArg (L _ arg) } <- arg1 - , Just sig_ty <- obviousSig arg -- A type sig on the arg disambiguates - = do { sig_tc_ty <- tcHsSigWcType (ExprSigCtxt NoRRC) sig_ty - ; finish_ambiguous_selector lbl sig_tc_ty } - - | Just res_ty <- mb_res_ty - , Just (arg_ty,_) <- tcSplitFunTy_maybe res_ty - = finish_ambiguous_selector lbl (scaledThing arg_ty) - - | otherwise - = ambiguousSelector lbl - -finish_ambiguous_selector :: LocatedN RdrName -> Type -> TcM Name -finish_ambiguous_selector lr@(L _ rdr) parent_type - = do { fam_inst_envs <- tcGetFamInstEnvs - ; case tyConOf fam_inst_envs parent_type of { - Nothing -> ambiguousSelector lr ; - Just p -> - - do { xs <- lookupParents True rdr - ; let parent = RecSelData p - ; case lookup parent xs of { - Nothing -> failWithTc (fieldNotInType parent rdr) ; - Just gre -> - - -- See Note [Unused name reporting and HasField] in GHC.Tc.Instance.Class - do { addUsedGRE True gre - ; keepAlive (greMangledName gre) - -- See Note [Deprecating ambiguous fields] - ; warnIfFlag Opt_WarnAmbiguousFields True $ - vcat [ text "The field" <+> quotes (ppr rdr) - <+> text "belonging to type" <+> ppr parent_type - <+> text "is ambiguous." - , text "This will not be supported by -XDuplicateRecordFields in future releases of GHC." - , if isLocalGRE gre - then text "You can use explicit case analysis to resolve the ambiguity." - else text "You can use a qualified import or explicit case analysis to resolve the ambiguity." - ] - ; return (greMangledName gre) } } } } } - --- This field name really is ambiguous, so add a suitable "ambiguous --- occurrence" error, then give up. -ambiguousSelector :: LocatedN RdrName -> TcM a -ambiguousSelector (L _ rdr) - = do { addAmbiguousNameErr rdr - ; failM } - --- | This name really is ambiguous, so add a suitable "ambiguous --- occurrence" error, then continue -addAmbiguousNameErr :: RdrName -> TcM () -addAmbiguousNameErr rdr - = do { env <- getGlobalRdrEnv - ; let gres = lookupGRE_RdrName rdr env - ; case gres of - [] -> panic "addAmbiguousNameErr: not found" - gre : gres -> setErrCtxt [] $ addNameClashErrRn rdr $ gre NE.:| gres} -- A type signature on the argument of an ambiguous record selector or -- the record expression in an update must be "obvious", i.e. the diff --git a/compiler/GHC/Tc/Types/Origin.hs b/compiler/GHC/Tc/Types/Origin.hs index 668dbb024c..f16a9cae39 100644 --- a/compiler/GHC/Tc/Types/Origin.hs +++ b/compiler/GHC/Tc/Types/Origin.hs @@ -500,7 +500,7 @@ exprCtOrigin (HsVar _ (L _ name)) = OccurrenceOf name exprCtOrigin (HsGetField _ _ (L _ f)) = HasFieldOrigin (unLoc $ hflLabel f) exprCtOrigin (HsUnboundVar {}) = Shouldn'tHappenOrigin "unbound variable" exprCtOrigin (HsConLikeOut {}) = panic "exprCtOrigin HsConLikeOut" -exprCtOrigin (HsRecFld _ f) = OccurrenceOfRecSel (rdrNameAmbiguousFieldOcc f) +exprCtOrigin (HsRecFld _ f) = OccurrenceOfRecSel (unLoc $ foLabel f) exprCtOrigin (HsOverLabel _ l) = OverLabelOrigin l exprCtOrigin (ExplicitList {}) = ListOrigin exprCtOrigin (HsIPVar _ ip) = IPOccOrigin ip diff --git a/compiler/GHC/Tc/Utils/Zonk.hs b/compiler/GHC/Tc/Utils/Zonk.hs index 96118af3b3..6dd199b128 100644 --- a/compiler/GHC/Tc/Utils/Zonk.hs +++ b/compiler/GHC/Tc/Utils/Zonk.hs @@ -805,10 +805,8 @@ zonkExpr env (HsUnboundVar her occ) ty' <- zonkTcTypeToTypeX env ty return (HER ref ty' u) -zonkExpr env (HsRecFld _ (Ambiguous v occ)) - = return (HsRecFld noExtField (Ambiguous (zonkIdOcc env v) occ)) -zonkExpr env (HsRecFld _ (Unambiguous v occ)) - = return (HsRecFld noExtField (Unambiguous (zonkIdOcc env v) occ)) +zonkExpr env (HsRecFld _ (FieldOcc v occ)) + = return (HsRecFld noExtField (FieldOcc (zonkIdOcc env v) occ)) zonkExpr _ e@(HsConLikeOut {}) = return e diff --git a/compiler/Language/Haskell/Syntax/Binds.hs b/compiler/Language/Haskell/Syntax/Binds.hs index 8c69f10eb8..60ca3fad1b 100644 --- a/compiler/Language/Haskell/Syntax/Binds.hs +++ b/compiler/Language/Haskell/Syntax/Binds.hs @@ -33,6 +33,7 @@ import {-# SOURCE #-} Language.Haskell.Syntax.Pat import Language.Haskell.Syntax.Extension import Language.Haskell.Syntax.Type +import GHC.Types.Name.Reader(RdrName) import GHC.Tc.Types.Evidence import GHC.Core.Type import GHC.Types.Basic @@ -931,7 +932,7 @@ when we have a different name for the local and top-level binder, making the distinction between the two names clear. -} -instance Outputable (RecordPatSynField a) where +instance Outputable (XRec a RdrName) => Outputable (RecordPatSynField a) where ppr (RecordPatSynField { recordPatSynField = v }) = ppr v diff --git a/compiler/Language/Haskell/Syntax/Expr.hs b/compiler/Language/Haskell/Syntax/Expr.hs index e7756cc804..17a0929976 100644 --- a/compiler/Language/Haskell/Syntax/Expr.hs +++ b/compiler/Language/Haskell/Syntax/Expr.hs @@ -265,6 +265,24 @@ is Less Cool because typecheck do-notation with (>>=) :: m1 a -> (a -> m2 b) -> m2 b.) -} +{- +Note [Non-overloaded record field selectors] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + data T = MkT { x,y :: Int } + f r x = x + y r + +This parses with HsVar for x, y, r on the RHS of f. Then, if +-XOverloadedRecordFields is /off/, the renamer recognises that y in +the RHS of f is really a record selector, and changes it to a +HsRecFld. In contrast x is locally bound, shadowing the record +selector, and stay as an HsVar. + +The renamer adds the Name of the record selector into the XRecFld +extension field, The typechecker keeps HsRecFld as HsRecFld, and +transforms the record-selector Name to an Id. +-} + -- | A Haskell expression. data HsExpr p = HsVar (XVar p) @@ -287,10 +305,8 @@ data HsExpr p -- HsVar for pretty printing | HsRecFld (XRecFld p) - (AmbiguousFieldOcc p) -- ^ Variable pointing to record selector - -- The parser produces HsVars - -- The renamer renames record-field selectors to HsRecFld - -- The typechecker preserves HsRecFld + (FieldOcc p) -- ^ Variable pointing to record selector + -- See Note [Non-overloaded record field selectors] | HsOverLabel (XOverLabel p) FastString -- ^ Overloaded label (Note [Overloaded labels] in GHC.OverloadedLabels) diff --git a/compiler/Language/Haskell/Syntax/Pat.hs b/compiler/Language/Haskell/Syntax/Pat.hs index 4417026478..a7fb5d8640 100644 --- a/compiler/Language/Haskell/Syntax/Pat.hs +++ b/compiler/Language/Haskell/Syntax/Pat.hs @@ -345,7 +345,7 @@ hsRecFieldsArgs :: forall p arg. UnXRec p => HsRecFields p arg -> [arg] hsRecFieldsArgs rbinds = map (hsRecFieldArg . unXRec @p) (rec_flds rbinds) hsRecFieldSel :: HsRecField pass arg -> Located (XCFieldOcc pass) -hsRecFieldSel = fmap extFieldOcc . hsRecFieldLbl +hsRecFieldSel = fmap foExt . hsRecFieldLbl {- diff --git a/compiler/Language/Haskell/Syntax/Type.hs b/compiler/Language/Haskell/Syntax/Type.hs index f23072c04a..f7ebe42da0 100644 --- a/compiler/Language/Haskell/Syntax/Type.hs +++ b/compiler/Language/Haskell/Syntax/Type.hs @@ -6,6 +6,7 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeApplications #-} {-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow] -- in module Language.Haskell.Syntax.Extension {- @@ -1248,31 +1249,34 @@ type LFieldOcc pass = XRec pass (FieldOcc pass) -- | Field Occurrence -- --- Represents an *occurrence* of an unambiguous field. This may or may not be a +-- Represents an *occurrence* of a field. This may or may not be a -- binding occurrence (e.g. this type is used in 'ConDeclField' and --- 'RecordPatSynField' which bind their fields, but also in 'HsRecField' for --- record construction and patterns, which do not). +-- 'RecordPatSynField' which bind their fields, but also in +-- 'HsRecField' for record construction and patterns, which do not). -- --- We store both the 'RdrName' the user originally wrote, and after the renamer, --- the selector function. -data FieldOcc pass = FieldOcc { extFieldOcc :: XCFieldOcc pass - , rdrNameFieldOcc :: LocatedN RdrName - -- ^ See Note [Located RdrNames] in "GHC.Hs.Expr" - } - - | XFieldOcc - !(XXFieldOcc pass) - -deriving instance (Eq (XCFieldOcc pass), Eq (XXFieldOcc pass)) => Eq (FieldOcc pass) +-- We store both the 'RdrName' the user originally wrote, and after +-- the renamer we use the extension field to store the selector +-- function. +data FieldOcc pass + = FieldOcc { + foExt :: XCFieldOcc pass + , foLabel :: XRec pass RdrName -- See Note [Located RdrNames] in Language.Haskell.Syntax.Expr + } + | XFieldOcc !(XXFieldOcc pass) +deriving instance ( + Eq (XRec pass RdrName) + , Eq (XCFieldOcc pass) + , Eq (XXFieldOcc pass) + ) => Eq (FieldOcc pass) -instance Outputable (FieldOcc pass) where - ppr = ppr . rdrNameFieldOcc +instance Outputable (XRec pass RdrName) => Outputable (FieldOcc pass) where + ppr = ppr . foLabel -instance OutputableBndr (FieldOcc pass) where - pprInfixOcc = pprInfixOcc . unLoc . rdrNameFieldOcc - pprPrefixOcc = pprPrefixOcc . unLoc . rdrNameFieldOcc +instance (UnXRec pass, OutputableBndr (XRec pass RdrName)) => OutputableBndr (FieldOcc pass) where + pprInfixOcc = pprInfixOcc . unXRec @pass . foLabel + pprPrefixOcc = pprPrefixOcc . unXRec @pass . foLabel -instance OutputableBndr (GenLocated SrcSpan (FieldOcc pass)) where +instance (UnXRec pass, OutputableBndr (XRec pass RdrName)) => OutputableBndr (GenLocated SrcSpan (FieldOcc pass)) where pprInfixOcc = pprInfixOcc . unLoc pprPrefixOcc = pprPrefixOcc . unLoc @@ -1285,9 +1289,8 @@ instance OutputableBndr (GenLocated SrcSpan (FieldOcc pass)) where -- (for unambiguous occurrences) or the typechecker (for ambiguous -- occurrences). -- --- See Note [HsRecField and HsRecUpdField] in "GHC.Hs.Pat" and --- Note [Disambiguating record fields] in "GHC.Tc.Gen.Head". --- See Note [Located RdrNames] in "GHC.Hs.Expr" +-- See Note [HsRecField and HsRecUpdField] in "GHC.Hs.Pat". +-- See Note [Located RdrNames] in "GHC.Hs.Expr". data AmbiguousFieldOcc pass = Unambiguous (XUnambiguous pass) (LocatedN RdrName) | Ambiguous (XAmbiguous pass) (LocatedN RdrName) diff --git a/testsuite/tests/backpack/should_compile/T13323.stderr b/testsuite/tests/backpack/should_compile/T13323.stderr deleted file mode 100644 index 7e637d9dd4..0000000000 --- a/testsuite/tests/backpack/should_compile/T13323.stderr +++ /dev/null @@ -1,24 +0,0 @@ -[1 of 3] Processing p - [1 of 2] Compiling A[sig] ( p/A.hsig, nothing ) - [2 of 2] Compiling P ( p/P.hs, nothing ) - -T13323.bkp:9:13: warning: [-Wambiguous-fields (in -Wdefault)] - The field ‘foo’ belonging to type A is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use a qualified import or explicit case analysis to resolve the ambiguity. -[2 of 3] Processing q - Instantiating q - [1 of 1] Compiling A ( q/A.hs, T13323.out/q/A.o ) -[3 of 3] Processing r - Instantiating r - [1 of 1] Including p[A=q:A] - Instantiating p[A=q:A] - [1 of 2] Compiling A[sig] ( p/A.hsig, T13323.out/p/p-HVmFlcYSefiK5n1aDP1v7x/A.o ) - [2 of 2] Compiling P ( p/P.hs, T13323.out/p/p-HVmFlcYSefiK5n1aDP1v7x/P.o ) - -T13323.bkp:9:13: warning: [-Wambiguous-fields (in -Wdefault)] - The field ‘foo’ belonging to type A is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use a qualified import or explicit case analysis to resolve the ambiguity. - [1 of 2] Compiling R ( r/R.hs, T13323.out/r/R.o ) - [2 of 2] Instantiating p diff --git a/testsuite/tests/backpack/should_compile/all.T b/testsuite/tests/backpack/should_compile/all.T index a747a461a4..628ddddf3d 100644 --- a/testsuite/tests/backpack/should_compile/all.T +++ b/testsuite/tests/backpack/should_compile/all.T @@ -57,6 +57,5 @@ test('T13140', normal, backpack_compile, ['']) test('T13149', expect_broken(13149), backpack_compile, ['']) test('T13214', normal, backpack_compile, ['']) test('T13250', normal, backpack_compile, ['']) -test('T13323', normal, backpack_compile, ['']) test('T19244a', expect_broken(19244), backpack_compile, ['']) test('T19244b', expect_broken(19244), backpack_compile, ['']) diff --git a/testsuite/tests/backpack/should_compile/T13323.bkp b/testsuite/tests/backpack/should_fail/T13323.bkp index 70a1ccf89c..70a1ccf89c 100644 --- a/testsuite/tests/backpack/should_compile/T13323.bkp +++ b/testsuite/tests/backpack/should_fail/T13323.bkp diff --git a/testsuite/tests/backpack/should_fail/T13323.stderr b/testsuite/tests/backpack/should_fail/T13323.stderr new file mode 100644 index 0000000000..cc8a9dded0 --- /dev/null +++ b/testsuite/tests/backpack/should_fail/T13323.stderr @@ -0,0 +1,5 @@ +[1 of 3] Processing p + [1 of 2] Compiling A[sig] ( p/A.hsig, nothing ) + [2 of 2] Compiling P ( p/P.hs, nothing ) + +T13323.bkp:9:13: Ambiguous field selector occurence: foo diff --git a/testsuite/tests/backpack/should_fail/all.T b/testsuite/tests/backpack/should_fail/all.T index 5e0d6fdeea..209796ee9c 100644 --- a/testsuite/tests/backpack/should_fail/all.T +++ b/testsuite/tests/backpack/should_fail/all.T @@ -49,3 +49,4 @@ test('bkpfail50', normal, backpack_compile_fail, ['']) test('bkpfail51', normal, backpack_compile_fail, ['']) test('bkpfail52', normal, backpack_compile_fail, ['']) test('bkpfail53', normal, backpack_compile_fail, ['']) +test('T13323', normal, backpack_compile_fail, ['']) diff --git a/testsuite/tests/overloadedrecflds/should_fail/DRFUnused.stderr b/testsuite/tests/overloadedrecflds/should_fail/DRFUnused.stderr index 7e75f5c8c7..87359fbb64 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/DRFUnused.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/DRFUnused.stderr @@ -1,8 +1,2 @@ -DRFUnused.hs:10:16: error: [-Wunused-top-binds (in -Wextra, -Wunused-binds), -Werror=unused-top-binds] - Defined but not used: ‘foo’ - -DRFUnused.hs:18:5: warning: [-Wambiguous-fields (in -Wdefault)] - The field ‘foo’ belonging to type U is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use explicit case analysis to resolve the ambiguity. +DRFUnused.hs:18:5: Ambiguous field selector occurence: foo diff --git a/testsuite/tests/overloadedrecflds/should_fail/T11167_ambiguous_fixity.stderr b/testsuite/tests/overloadedrecflds/should_fail/T11167_ambiguous_fixity.stderr index 2a107d6570..4d1e1262d7 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/T11167_ambiguous_fixity.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/T11167_ambiguous_fixity.stderr @@ -2,15 +2,5 @@ [2 of 3] Compiling T11167_ambiguous_fixity_B ( T11167_ambiguous_fixity_B.hs, T11167_ambiguous_fixity_B.o ) [3 of 3] Compiling T11167_ambiguous_fixity ( T11167_ambiguous_fixity.hs, T11167_ambiguous_fixity.o ) -T11167_ambiguous_fixity.hs:6:7: error: - Ambiguous fixity for record field ‘foo’ - Conflicts: - infixr 3 - imported from ‘T11167_ambiguous_fixity_A’ at T11167_ambiguous_fixity.hs:3:1-32 - (and originally defined at T11167_ambiguous_fixity_A.hs:4:16-18) - infixr 3 - imported from ‘T11167_ambiguous_fixity_A’ at T11167_ambiguous_fixity.hs:3:1-32 - (and originally defined at T11167_ambiguous_fixity_A.hs:3:16-18) - infixl 5 - imported from ‘T11167_ambiguous_fixity_B’ at T11167_ambiguous_fixity.hs:4:1-32 - (and originally defined at T11167_ambiguous_fixity_B.hs:2:16-18) +T11167_ambiguous_fixity.hs:6:16: + Ambiguous field selector occurence: foo diff --git a/testsuite/tests/overloadedrecflds/should_fail/T13132_duplicaterecflds.stderr b/testsuite/tests/overloadedrecflds/should_fail/T13132_duplicaterecflds.stderr index 391ccde4c1..a2db6ed86b 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/T13132_duplicaterecflds.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/T13132_duplicaterecflds.stderr @@ -1,6 +1,6 @@ -T13132_duplicaterecflds.hs:9:11: error: - The operator ‘runContT’ [infixl 9] of a section - must have lower precedence than that of the operand, - namely ‘y’ [infixl 9] - in the section: ‘`runContT` x `y` x’ +T13132_duplicaterecflds.hs:7:16: + Ambiguous field selector occurence: runContT + +T13132_duplicaterecflds.hs:9:12: + Ambiguous field selector occurence: runContT diff --git a/testsuite/tests/overloadedrecflds/should_fail/all.T b/testsuite/tests/overloadedrecflds/should_fail/all.T index 8400644908..ba872c9915 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/all.T +++ b/testsuite/tests/overloadedrecflds/should_fail/all.T @@ -46,3 +46,4 @@ test('NFSDuplicate', normal, compile_fail, ['']) test('NFSExport', normal, compile_fail, ['']) test('T18999_NoDisambiguateRecordFields', normal, compile_fail, ['']) test('DRFUnused', normal, compile_fail, ['']) +test('overloadedrecfldswasrunnowfail06', normal, compile_fail, ['']) diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail02.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail02.stderr index 9c2057e17d..c47c980055 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail02.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail02.stderr @@ -1,6 +1,3 @@ overloadedrecfldsfail02.hs:8:18: error: - Ambiguous occurrence ‘x’ - It could refer to either the field ‘x’, - defined at overloadedrecfldsfail02.hs:6:16 - or the field ‘x’, defined at overloadedrecfldsfail02.hs:5:16 + Ambiguous field selector occurence: x diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail04.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail04.stderr index 0c58ad7164..738fb06eeb 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail04.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail04.stderr @@ -2,10 +2,4 @@ [2 of 2] Compiling Main ( overloadedrecfldsfail04.hs, overloadedrecfldsfail04.o ) overloadedrecfldsfail04.hs:9:6: error: - Ambiguous occurrence ‘I.x’ - It could refer to either the field ‘x’, - imported from ‘OverloadedRecFldsFail04_A’ at overloadedrecfldsfail04.hs:6:1-37 - (and originally defined at OverloadedRecFldsFail04_A.hs:6:16) - or the field ‘x’, - imported from ‘OverloadedRecFldsFail04_A’ at overloadedrecfldsfail04.hs:6:1-37 - (and originally defined at OverloadedRecFldsFail04_A.hs:5:16) + Ambiguous field selector occurence: I.x diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail11.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail11.stderr index a5cc4e8197..fbb1bd05fd 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail11.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail11.stderr @@ -1,12 +1,5 @@ [1 of 2] Compiling OverloadedRecFldsFail11_A ( OverloadedRecFldsFail11_A.hs, OverloadedRecFldsFail11_A.o ) [2 of 2] Compiling Main ( overloadedrecfldsfail11.hs, overloadedrecfldsfail11.o ) -overloadedrecfldsfail11.hs:5:15: error: [-Wambiguous-fields (in -Wdefault), -Werror=ambiguous-fields] - The field ‘foo’ belonging to type S is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use a qualified import or explicit case analysis to resolve the ambiguity. - -overloadedrecfldsfail11.hs:5:15: error: [-Wdeprecations (in -Wdefault), -Werror=deprecations] - In the use of ‘foo’ (imported from OverloadedRecFldsFail11_A): - "Warning on a record field" - +overloadedrecfldsfail11.hs:5:15: + Ambiguous field selector occurence: foo diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail12.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail12.stderr index be3d3d6f8d..e31859c35a 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail12.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail12.stderr @@ -1,24 +1,8 @@ [1 of 2] Compiling OverloadedRecFldsFail12_A ( OverloadedRecFldsFail12_A.hs, OverloadedRecFldsFail12_A.o ) [2 of 2] Compiling Main ( overloadedrecfldsfail12.hs, overloadedrecfldsfail12.o ) -overloadedrecfldsfail12.hs:10:11: error: [-Wdeprecations (in -Wdefault), -Werror=deprecations] - In the use of ‘foo’ (imported from OverloadedRecFldsFail12_A): - "Deprecated foo" +overloadedrecfldsfail12.hs:13:5: + Ambiguous field selector occurence: foo -overloadedrecfldsfail12.hs:10:20: error: [-Wdeprecations (in -Wdefault), -Werror=deprecations] - In the use of ‘bar’ (imported from OverloadedRecFldsFail12_A): - "Deprecated bar" - -overloadedrecfldsfail12.hs:13:5: error: [-Wambiguous-fields (in -Wdefault), -Werror=ambiguous-fields] - The field ‘foo’ belonging to type T is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use a qualified import or explicit case analysis to resolve the ambiguity. - -overloadedrecfldsfail12.hs:13:5: error: [-Wdeprecations (in -Wdefault), -Werror=deprecations] - In the use of ‘foo’ (imported from OverloadedRecFldsFail12_A): - "Deprecated foo" - -overloadedrecfldsfail12.hs:16:5: error: [-Wambiguous-fields (in -Wdefault), -Werror=ambiguous-fields] - The field ‘foo’ belonging to type S is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use explicit case analysis to resolve the ambiguity. +overloadedrecfldsfail12.hs:16:5: + Ambiguous field selector occurence: foo diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail13.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail13.stderr index 7c61ab769e..6fa12a9041 100644 --- a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail13.stderr +++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldsfail13.stderr @@ -1,22 +1,12 @@ -overloadedrecfldsfail13.hs:10:5: error: - ‘x’ is not a (visible) field of type ‘U’ - In the expression: x (MkU :: U) - In an equation for ‘a’: a = x (MkU :: U) + overloadedrecfldsfail13.hs:10:5: + Ambiguous field selector occurence: x -overloadedrecfldsfail13.hs:12:5: error: - Ambiguous occurrence ‘x’ - It could refer to either the field ‘x’, - defined at overloadedrecfldsfail13.hs:7:16 - or the field ‘x’, defined at overloadedrecfldsfail13.hs:6:16 + overloadedrecfldsfail13.hs:12:5: + Ambiguous field selector occurence: x -overloadedrecfldsfail13.hs:15:5: error: - ‘x’ is not a (visible) field of type ‘U’ - In the expression: x - In an equation for ‘c’: c = x + overloadedrecfldsfail13.hs:15:5: + Ambiguous field selector occurence: x -overloadedrecfldsfail13.hs:18:5: error: - Ambiguous occurrence ‘x’ - It could refer to either the field ‘x’, - defined at overloadedrecfldsfail13.hs:7:16 - or the field ‘x’, defined at overloadedrecfldsfail13.hs:6:16 + overloadedrecfldsfail13.hs:18:5: + Ambiguous field selector occurence: x diff --git a/testsuite/tests/overloadedrecflds/should_run/overloadedrecfldsrun06.hs b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldswasrunnowfail06.hs index 92f870833d..92f870833d 100644 --- a/testsuite/tests/overloadedrecflds/should_run/overloadedrecfldsrun06.hs +++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldswasrunnowfail06.hs diff --git a/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldswasrunnowfail06.stderr b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldswasrunnowfail06.stderr new file mode 100644 index 0000000000..86a7b037ce --- /dev/null +++ b/testsuite/tests/overloadedrecflds/should_fail/overloadedrecfldswasrunnowfail06.stderr @@ -0,0 +1,12 @@ + +overloadedrecfldswasrunnowfail06.hs:11:11: + Ambiguous field selector occurence: x + +overloadedrecfldswasrunnowfail06.hs:13:11: + Ambiguous field selector occurence: x + +overloadedrecfldswasrunnowfail06.hs:15:13: + Ambiguous field selector occurence: x + +overloadedrecfldswasrunnowfail06.hs:21:20: + Ambiguous field selector occurence: x diff --git a/testsuite/tests/overloadedrecflds/should_run/all.T b/testsuite/tests/overloadedrecflds/should_run/all.T index 4267c10d5e..8d6d9850bb 100644 --- a/testsuite/tests/overloadedrecflds/should_run/all.T +++ b/testsuite/tests/overloadedrecflds/should_run/all.T @@ -5,7 +5,6 @@ test('overloadedrecfldsrun02', [extra_files(['OverloadedRecFldsRun02_A.hs'])], m test('overloadedrecfldsrun03', normal, compile_and_run, ['']) test('overloadedrecfldsrun04', omit_ways(prof_ways), compile_and_run, ['']) test('overloadedrecfldsrun05', normal, compile_and_run, ['']) -test('overloadedrecfldsrun06', normal, compile_and_run, ['']) test('overloadedrecfldsrun07', normal, compile_and_run, ['']) test('overloadedrecflds_generics', normal, compile_and_run, ['']) test('overloadedlabelsrun01', normal, compile_and_run, ['']) diff --git a/testsuite/tests/overloadedrecflds/should_run/overloadedrecfldsrun06.stdout b/testsuite/tests/overloadedrecflds/should_run/overloadedrecfldsrun06.stdout deleted file mode 100644 index abc4e3b957..0000000000 --- a/testsuite/tests/overloadedrecflds/should_run/overloadedrecfldsrun06.stdout +++ /dev/null @@ -1,2 +0,0 @@ -42 -True diff --git a/testsuite/tests/rename/should_compile/T11167_ambig.stderr b/testsuite/tests/rename/should_compile/T11167_ambig.stderr deleted file mode 100644 index 5320b42149..0000000000 --- a/testsuite/tests/rename/should_compile/T11167_ambig.stderr +++ /dev/null @@ -1,11 +0,0 @@ - -T11167_ambig.hs:10:13: warning: [-Wambiguous-fields (in -Wdefault)] - The field ‘runContT’ belonging to type ContT r m a is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use explicit case analysis to resolve the ambiguity. - -T11167_ambig.hs:17:9: warning: [-Wambiguous-fields (in -Wdefault)] - The field ‘runContT’ belonging to type forall a. - ContT () IO a is ambiguous. - This will not be supported by -XDuplicateRecordFields in future releases of GHC. - You can use explicit case analysis to resolve the ambiguity. diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T index 92464ca55b..56521084d7 100644 --- a/testsuite/tests/rename/should_compile/all.T +++ b/testsuite/tests/rename/should_compile/all.T @@ -145,7 +145,6 @@ test('T9778', normal, compile, ['-fwarn-unticked-promoted-constructors']) test('T10816', normal, compile, ['']) test('T11164', [], multimod_compile, ['T11164', '-v0']) test('T11167', normal, compile, ['']) -test('T11167_ambig', normal, compile, ['']) test('T10625', normal, compile, ['']) test('T11624', [], multimod_compile, ['T11624', '']) test('T11662', [], multimod_compile, ['T11662', '-v0']) diff --git a/testsuite/tests/rename/should_compile/T11167_ambig.hs b/testsuite/tests/rename/should_fail/T11167_ambig.hs index 74df05e5ee..74df05e5ee 100644 --- a/testsuite/tests/rename/should_compile/T11167_ambig.hs +++ b/testsuite/tests/rename/should_fail/T11167_ambig.hs diff --git a/testsuite/tests/rename/should_fail/T11167_ambig.stderr b/testsuite/tests/rename/should_fail/T11167_ambig.stderr new file mode 100644 index 0000000000..f8310ad214 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T11167_ambig.stderr @@ -0,0 +1,6 @@ + +T11167_ambig.hs:10:13: + Ambiguous field selector occurence: runContT + +T11167_ambig.hs:17:9: + Ambiguous field selector occurence: runContT diff --git a/testsuite/tests/rename/should_fail/all.T b/testsuite/tests/rename/should_fail/all.T index 475aef9c6c..f1344bc300 100644 --- a/testsuite/tests/rename/should_fail/all.T +++ b/testsuite/tests/rename/should_fail/all.T @@ -164,3 +164,4 @@ test('T18240a', normal, compile_fail, ['']) test('T18240b', normal, compile_fail, ['']) test('T18740a', normal, compile_fail, ['']) test('T18740b', normal, compile_fail, ['']) +test('T11167_ambig', normal, compile_fail, ['']) diff --git a/utils/haddock b/utils/haddock -Subproject cafb48118f7c111020663776845897e225607b4 +Subproject 7d27ea7a87056c315015dcd6b225edbc6f13b1a |