Tuples cannot contain unboxed types
authorsimonpj@microsoft.com <unknown>
Thu, 15 May 2008 11:53:32 +0000 (11:53 +0000)
committersimonpj@microsoft.com <unknown>
Thu, 15 May 2008 11:53:32 +0000 (11:53 +0000)
This bug allowed, for example

  f = let x = ( 1#, 'x' ) in x

which is ill-typed because you can't put an unboxed value in a tuple.
Core Lint fails on this program.

The patch makes the program be rejcted up-front.

compiler/typecheck/TcExpr.lhs

index b844a2a..32223a5 100644 (file)
@@ -314,7 +314,9 @@ tcExpr in_expr@(ExplicitPArr _ exprs) res_ty        -- maybe empty
 --        The scrutinee should have a rigid type if x,y do
 -- The general scheme is the same as in tcIdApp
 tcExpr (ExplicitTuple exprs boxity) res_ty
-  = do { tvs <- newBoxyTyVars [argTypeKind | e <- exprs]
+  = do { let kind = case boxity of { Boxed   -> liftedTypeKind
+                                   ; Unboxed -> argTypeKind }
+       ; tvs <- newBoxyTyVars [kind | e <- exprs]
        ; let tup_tc     = tupleTyCon boxity (length exprs)
              tup_res_ty = mkTyConApp tup_tc (mkTyVarTys tvs)
        ; checkWiredInTyCon tup_tc      -- Ensure instances are available