diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2013-11-28 17:56:53 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-11-29 07:31:40 +0000 |
commit | 59e17d6ef71c29f4e114e55be83f1b3722f04139 (patch) | |
tree | c4ce5e04a686dff34a77714d1680151ed675d662 | |
parent | f3a841612e754536d635e8c970fb67453fb57cab (diff) | |
download | haskell-59e17d6ef71c29f4e114e55be83f1b3722f04139.tar.gz |
Fail (rather than addErr) if you use a bogus field in a pattern
This fixes Trac #8570
-rw-r--r-- | compiler/typecheck/TcPat.lhs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/compiler/typecheck/TcPat.lhs b/compiler/typecheck/TcPat.lhs index f43fe3dea0..957f0d63de 100644 --- a/compiler/typecheck/TcPat.lhs +++ b/compiler/typecheck/TcPat.lhs @@ -850,19 +850,15 @@ tcConArgs data_con arg_tys (RecCon (HsRecFields rpats dd)) penv thing_inside = case [ty | (f,ty) <- field_tys, f == field_lbl] of -- No matching field; chances are this field label comes from some - -- other record type (or maybe none). As well as reporting an - -- error we still want to typecheck the pattern, principally to - -- make sure that all the variables it binds are put into the - -- environment, else the type checker crashes later: + -- other record type (or maybe none). If this happens, just fail, + -- otherwise we get crashes later (Trac #8570), and similar: -- f (R { foo = (a,b) }) = a+b -- If foo isn't one of R's fields, we don't want to crash when -- typechecking the "a+b". - [] -> do { addErrTc (badFieldCon data_con field_lbl) - ; bogus_ty <- newFlexiTyVarTy liftedTypeKind - ; return (error "Bogus selector Id", bogus_ty) } + [] -> failWith (badFieldCon data_con field_lbl) -- The normal case, when the field comes from the right constructor - (pat_ty : extras) -> + (pat_ty : extras) -> ASSERT( null extras ) do { sel_id <- tcLookupField field_lbl ; return (sel_id, pat_ty) } |