@@ -572,7 +572,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
572572 putIState (ist { idris_optimisation = opts })
573573 addIBC (IBCOpt n)
574574 ist <- getIState
575− let pats = doTransforms ist pats_in
575+ let pats = map (simple_lhs (tt_ctxt ist)) $ doTransforms ist pats_in
576576
577577 -- logLvl 3 (showSep "\n" (map (\ (l,r) ->
578578 -- show l ++ " = " ++
@@ -591,7 +591,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
591591 -- pdef is the compile-time pattern definition.
592592 -- This will get further optimised for run-time, and, separately,
593593 -- further inlined to help with totality checking.
594− let pdef = map debind $ map (simple_lhs (tt_ctxt ist)) pats
594+ let pdef = map debind pats
595595
596596 logLvl 5 $ "Initial typechecked patterns:\n" ++ show pats
597597 logLvl 5 $ "Initial typechecked pattern def:\n" ++ show pdef
@@ -628,7 +628,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
628628 Just _ -> logLvl 5 $ "Partially evaluated:\n" ++ show pats
629629 _ -> return ()
630630
631− let optpdef = map debind $ map (simple_lhs (tt_ctxt ist)) optpats
631+ let optpdef = map debind optpats -- $ map (simple_lhs (tt_ctxt ist)) optpats
632632 tree@(CaseDef scargs sc _) <- tclift $
633633 simpleCase tcase False reflect CompileTime fc pdef
634634 cov <- coverage
@@ -737,11 +737,21 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
737737
738738 getLHS (_, l, _) = l
739739
740− simple_lhs ctxt (Right (x, y)) = Right (normalise ctxt [] x, y)
740+ simple_lhs ctxt (Right (x, y)) = Right (normalise ctxt [] x,
741+ normalisePats ctxt [] y)
741742 simple_lhs ctxt t = t
742743
743744 simple_rt ctxt (p, x, y) = (p, x, rt_simplify ctxt [] y)
744745
746+ -- this is so pattern types are in the right form for erasure
747+ normalisePats ctxt env (Bind n (PVar t) sc)
748+ = let t' = normalise ctxt env t in
749+ Bind n (PVar t') (normalisePats ctxt ((n, PVar t') : env) sc)
750+ normalisePats ctxt env (Bind n (PVTy t) sc)
751+ = let t' = normalise ctxt env t in
752+ Bind n (PVTy t') (normalisePats ctxt ((n, PVar t') : env) sc)
753+ normalisePats ctxt env t = t
754+
745755 specNames [] = Nothing
746756 specNames (Specialise ns : _) = Just ns
747757 specNames (_ : xs) = specNames xs