@@ -161,10 +161,10 @@ addTyInferred n
161161 putIState $ i { idris_tyinfodata =
162162 addDef n TIPartial (idris_tyinfodata i) }
163163
164−addTyInfConstraints :: [(Term, Term)] -> Idris ()
165−addTyInfConstraints ts = do logLvl 2 $ "TI missing: " ++ show ts
166− mapM_ addConstraint ts
167− return ()
164+addTyInfConstraints :: FC -> [(Term, Term)] -> Idris ()
165+addTyInfConstraints fc ts = do logLvl 2 $ "TI missing: " ++ show ts
166+ mapM_ addConstraint ts
167+ return ()
168168 where addConstraint (x, y) = findMVApps x y
169169
170170 findMVApps x y
@@ -189,7 +189,8 @@ addTyInfConstraints ts = do logLvl 2 $ "TI missing: " ++ show ts
189189 logLvl 1 $ "TI constraint: " ++ show (n, t)
190190 case lookupCtxt n (idris_tyinfodata ist) of
191191 [TISolution ts] ->
192− do let ti' = addDef n (TISolution (t : ts))
192+ do mapM_ (checkConsistent t) ts
193+ let ti' = addDef n (TISolution (t : ts))
193194 (idris_tyinfodata ist)
194195 put $ ist { idris_tyinfodata = ti' }
195196 _ ->
@@ -197,6 +198,25 @@ addTyInfConstraints ts = do logLvl 2 $ "TI missing: " ++ show ts
197198 (idris_tyinfodata ist)
198199 put $ ist { idris_tyinfodata = ti' }
199200
201+ -- Check a solution is consistent with previous solutions
202+ -- Meaning: If heads are both data types, they had better be the
203+ -- same.
204+ checkConsistent :: Term -> Term -> Idris ()
205+ checkConsistent x y =
206+ do let (fx, _) = unApply x
207+ let (fy, _) = unApply y
208+ case (fx, fy) of
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)
213+ _ -> return ()
214+
215+ where errWhen True
216+ = throwError (At fc
217+ (CantUnify False x y (Msg "") [] 0))
218+ errWhen False = return ()
219+
200220isTyInferred :: Name -> Idris Bool
201221isTyInferred n
202222 = do i <- getIState