@@ -19,7 +19,7 @@ import Data.List
1919-- only guessing! But we can still do some type-directed disambiguation of
2020-- names.
2121-- Constants (fromInteger/fromString etc) won't be supported, because in general
22- -- they involve resoling interfaces - they'll just become unmatchable patterns.
22+ -- they involve resolving interfaces - they'll just become unmatchable patterns.
2323
2424match : {auto c : Ref Ctxt Defs} ->
2525 ClosedNF -> (Name, Int, ClosedTerm) -> Core Bool
@@ -57,11 +57,11 @@ nextVar fc
5757 put QVar (i + 1 )
5858 pure (Ref fc Bound (MN " imp" i))
5959
60- badClause : ClosedTerm -> List RawImp -> List RawImp -> List (Name, RawImp) -> Core a
60+ badClause : { auto c : Ref Ctxt Defs} -> ClosedTerm -> List RawImp -> List RawImp -> List (Name, RawImp) -> Core a
6161badClause fn exps autos named
6262 = throw (GenericMsg (getLoc fn)
6363 (" Badly formed impossible clause "
64- ++ show (fn , exps, autos, named)))
64+ ++ show (! (toFullNames fn) , exps, autos, named)))
6565
6666mutual
6767 processArgs : {auto c : Ref Ctxt Defs} ->
@@ -115,6 +115,8 @@ mutual
115115 processArgs (App fc fn e') ! (sc defs (toClosure defaultOpts Env . empty e'))
116116 exps [] named'
117117 processArgs fn ty [] [] [] = pure fn
118+ processArgs fn ty (x :: _ ) autos named
119+ = throw $ GenericMsg (getFC x) " Too many arguments"
118120 processArgs fn ty exps autos named
119121 = badClause fn exps autos named
120122
@@ -129,11 +131,15 @@ mutual
129131 = do defs <- get Ctxt
130132 prims <- getPrimitiveNames
131133 when (n `elem` prims) $
132- throw (InternalError " Can't deal with constants here yet" )
134+ throw (GenericMsg fc " Can't deal with \{show n} in impossible clauses yet" )
133135
134136 gdefs <- lookupNameBy id n (gamma defs)
135- [(n', i, gdef)] <- dropNoMatch ! (traverseOpt (evalClosure defs) mty) gdefs
136- | ts => ambiguousName fc n (map fst ts)
137+ mty' <- traverseOpt (evalClosure defs) mty
138+ [(n', i, gdef)] <- dropNoMatch mty' gdefs
139+ | [] => if length gdefs == 0
140+ then undefinedName fc n
141+ else throw $ GenericMsg fc " \{show n} does not match expected type"
142+ | ts => throw $ AmbiguousName fc (map fst ts)
137143 tynf <- nf defs Env . empty (type gdef)
138144 -- #899 we need to make sure that type & data constructors are marked
139145 -- as such so that the coverage checker actually uses the matches in
@@ -165,6 +171,9 @@ mutual
165171 mkTerm (IMustUnify fc r tm) mty exps autos named
166172 = Erased fc . Dotted <$> mkTerm tm mty exps autos named
167173 mkTerm (IPrimVal fc c) _ _ _ _ = pure (PrimVal fc c)
174+ -- We're taking UniqueDefault here, _and_ we're falling through to nextVar otherwise, which is sketchy.
175+ -- On option is to try each and emit an AmbiguousElab? We maybe should respect `UniqueDefault` if there
176+ -- is no evidence (mty), but we should _try_ to resolve here if there is an mty.
168177 mkTerm (IAlternative _ (UniqueDefault tm) _ ) mty exps autos named
169178 = mkTerm tm mty exps autos named
170179 mkTerm tm _ _ _ _ = nextVar (getFC tm)
0 commit comments