[commit: ghc] master: Fail (rather than addErr) if you use a bogus field in a pattern (59e17d6)

git at git.haskell.org git at git.haskell.org
Fri Nov 29 07:31:57 UTC 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/59e17d6ef71c29f4e114e55be83f1b3722f04139/ghc

>---------------------------------------------------------------

commit 59e17d6ef71c29f4e114e55be83f1b3722f04139
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Nov 28 17:56:53 2013 +0000

    Fail (rather than addErr) if you use a bogus field in a pattern
    
    This fixes Trac #8570


>---------------------------------------------------------------

59e17d6ef71c29f4e114e55be83f1b3722f04139
 compiler/typecheck/TcPat.lhs |   10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/compiler/typecheck/TcPat.lhs b/compiler/typecheck/TcPat.lhs
index f43fe3d..957f0d6 100644
--- a/compiler/typecheck/TcPat.lhs
+++ b/compiler/typecheck/TcPat.lhs
@@ -850,16 +850,12 @@ 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) ->



More information about the ghc-commits mailing list