@@ -161,10 +161,10 @@ addTyInferred n
161 putIState $ i { idris_tyinfodata =
161 putIState $ i { idris_tyinfodata =
162 addDef n TIPartial (idris_tyinfodata i) }
162 addDef n TIPartial (idris_tyinfodata i) }
164−addTyInfConstraints :: [(Term, Term)] -> Idris ()
164+addTyInfConstraints :: FC -> [(Term, Term)] -> Idris ()
165−addTyInfConstraints ts = do logLvl 2 $ "TI missing: " ++ show ts
165+addTyInfConstraints fc ts = do logLvl 2 $ "TI missing: " ++ show ts
166− mapM_ addConstraint ts
166+ mapM_ addConstraint ts
167− return ()
167+ return ()
168 where addConstraint (x, y) = findMVApps x y
168 where addConstraint (x, y) = findMVApps x y
170 findMVApps x y
170 findMVApps x y
@@ -189,7 +189,8 @@ addTyInfConstraints ts = do logLvl 2 $ "TI missing: " ++ show ts
189 logLvl 1 $ "TI constraint: " ++ show (n, t)
189 logLvl 1 $ "TI constraint: " ++ show (n, t)
190 case lookupCtxt n (idris_tyinfodata ist) of
190 case lookupCtxt n (idris_tyinfodata ist) of
191 [TISolution ts] ->
191 [TISolution ts] ->
192+ do mapM_ (checkConsistent t) ts
192− do let ti' = addDef n (TISolution (t : ts))
193+ let ti' = addDef n (TISolution (t : ts))
193 (idris_tyinfodata ist)
194 (idris_tyinfodata ist)
194 put $ ist { idris_tyinfodata = ti' }
195 put $ ist { idris_tyinfodata = ti' }
@@ -197,6 +198,25 @@ addTyInfConstraints ts = do logLvl 2 $ "TI missing: " ++ show ts
197 (idris_tyinfodata ist)
198 (idris_tyinfodata ist)
198 put $ ist { idris_tyinfodata = ti' }
199 put $ ist { idris_tyinfodata = ti' }
201+ -- Check a solution is consistent with previous solutions
202+ -- Meaning: If heads are both data types, they had better be the
204+ checkConsistent :: Term -> Term -> Idris ()
205+ checkConsistent x y =
206+ do let (fx, _) = unApply x
207+ let (fy, _) = unApply y
209+ (P (TCon _ _) n _, P (TCon _ _) n' _) -> errWhen (n/=n)
210+ (P (TCon _ _) n _, Constant _) -> errWhen True
211+ (Constant _, P (TCon _ _) n' _) -> errWhen True
212+ (P (DCon _ _) n _, P (DCon _ _) n' _) -> errWhen (n/=n)
217+ (CantUnify False x y (Msg "") [] 0))
218+ errWhen False = return ()
200isTyInferred :: Name -> Idris Bool
220isTyInferred :: Name -> Idris Bool
201isTyInferred n
221isTyInferred n
202 = do i <- getIState
222 = do i <- getIState