@@ -299,7 +299,7 @@ getUniqueUsed ctxt tm = execState (getUniq [] [] tm) []
299299 OK (_, UType AllTypes) -> True
300300 _ -> False in
301301 do getUniqB env us b
302− getUniq ((n, Rig0, b):env) ((n, uniq):us) sc
302+ getUniq ((n, RigW, b):env) ((n, uniq):us) sc
303303 getUniq env us (App _ f a) = do getUniq env us f; getUniq env us a
304304 getUniq env us (V i)
305305 | i < length us = if snd (us!!i) then use (fst (us!!i)) else return ()
@@ -574,7 +574,7 @@ hasEmptyPat ctxt tyctxt (Bind n (PVar _ ty) sc)
574574hasEmptyPat ctxt tyctxt _ = False
575575
576576-- Find names which are applied to a function in a Rig1 position
577−findLinear :: IState -> [Name] -> Term -> [Name]
577+findLinear :: IState -> [Name] -> Term -> [(Name, RigCount)]
578578findLinear ist env tm | (P _ f _, args) <- unApply tm,
579579 f `notElem` env,
580580 Just ty_in <- lookupTyExact f (tt_ctxt ist)
@@ -582,7 +582,8 @@ findLinear ist env tm | (P _ f _, args) <- unApply tm,
582582 nub $ concatMap (findLinear ist env) args ++ findLinArg ty args
583583 where
584584 findLinArg (Bind n (Pi c _ _ _) sc) (P _ a _ : as)
585− | Rig1 <- c = a : findLinArg sc as
585+ | Rig0 <- c = (a, c) : findLinArg sc as
586+ | Rig1 <- c = (a, c) : findLinArg sc as
586587 findLinArg (Bind n (Pi _ _ _ _) sc) (a : as) = findLinArg sc as
587588 findLinArg _ _ = []
588589findLinear ist env (App _ f a)
@@ -590,10 +591,26 @@ findLinear ist env (App _ f a)
590591findLinear ist env (Bind n b sc) = findLinear ist (n : env) sc
591592findLinear ist _ _ = []
592593
593−setLinear :: [Name] -> Term -> Term
594+setLinear :: [(Name, RigCount)] -> Term -> Term
594595setLinear ns (Bind n b@(PVar r t) sc)
595− | n `elem` ns = Bind n (PVar Rig1 t) (setLinear ns sc)
596+ | Just r <- lookup n ns = Bind n (PVar r t) (setLinear ns sc)
596597 | otherwise = Bind n b (setLinear ns sc)
597598setLinear ns tm = tm
598599
600+-- Assume type is at least in whnfArgs form
601+linearCheck :: FC -> Type -> Idris ()
602+linearCheck fc t = do ist <- getIState
603+ checkArgs ist t
604+ where
605+ checkArgs ist (Bind n (Pi RigW _ ty _) sc)
606+ | (P _ f _, _) <- unApply ty
607+ = case lookupCtxtExact f (idris_datatypes ist) of
608+ Just ti | linear_con ti ->
609+ ierror $ At fc $
610+ Msg $ show ty ++ " has a linear constructor, so must have count <= 1"
611+ _ -> return ()
612+ checkArgs ist (Bind n (Pi _ _ _ _) sc)
613+ = checkArgs ist (substV (P Bound n Erased) sc)
614+ checkArgs ist _ = return ()
615+
599616