@@ -1622,7 +1622,13 @@ addImpl' inpat env infns imp_meths ist ptm
16221622-- if in a pattern, and there are no arguments, and there's no possible
16231623-- names with zero explicit arguments, don't add implicits.
16241624
1625−aiFn :: Bool -> Bool -> Bool -> [Name] -> IState -> FC -> Name -> FC -> [[T.Text]] -> [PArg] -> Either Err PTerm
1625+aiFn :: Bool -> Bool -> Bool
1626+ -> [Name]
1627+ -> IState -> FC
1628+ -> Name -- ^ function being applied
1629+ -> FC -> [[T.Text]]
1630+ -> [PArg] -> -- ^ initial arguments
1631+ Either Err PTerm
16261632aiFn inpat True qq imp_meths ist fc f ffc ds []
16271633 = case lookupDef f (tt_ctxt ist) of
16281634 [] -> Right $ PPatvar ffc f
@@ -1685,8 +1691,20 @@ aiFn inpat expat qq imp_meths ist fc f ffc ds as
16851691 Just (n,t) -> t
16861692 _ -> Public
16871693
1688− insertImpl :: [PArg] -> [PArg] -> [PArg]
1689− insertImpl ps as = insImpAcc M.empty ps (filter exp as) (filter (not . exp) as)
1694+ insertImpl :: [PArg] -- ^ expected argument types (from idris_implicits)
1695+ -> [PArg] -- ^ given arguments
1696+ -> [PArg]
1697+ insertImpl ps as
1698+ = let (as', badimpls) = partition (impIn ps) as in
1699+ map addUnknownImp badimpls ++
1700+ insImpAcc M.empty ps (filter exp as') (filter (not . exp) as')
1701+
1702+ -- return True if the second argument is an implicit argument which is
1703+ -- expected in the implicits, or if it's not an implicit
1704+ impIn :: [PArg] -> PArg -> Bool
1705+ impIn ps (PExp _ _ _ _) = True
1706+ impIn ps (PConstraint _ _ _ _) = True
1707+ impIn ps arg = any (\p -> pname arg == pname p) ps
16901708
16911709 exp (PExp _ _ _ _) = True
16921710 exp (PConstraint _ _ _ _) = True
@@ -1723,12 +1741,11 @@ aiFn inpat expat qq imp_meths ist fc f ffc ds as
17231741 insImpAcc (M.insert n Placeholder pnas) ps given imps
17241742 else PTacImplicit p l n sc sc :
17251743 insImpAcc (M.insert n sc pnas) ps given imps
1726− insImpAcc _ expected [] imps = imps -- so that unused implicits give error
1727− -- TODO: report here, and prune alternatives
1728− -- Issue #1740 in the Issue Tracker
1729−-- https://github.com/idris-lang/Idris-dev/issues/1740
1744+ insImpAcc _ expected [] imps = map addUnknownImp imps -- so that unused implicits give error
17301745 insImpAcc _ _ given imps = given ++ imps
17311746
1747+ addUnknownImp arg = arg { argopts = UnknownImp : argopts arg }
1748+
17321749 find n [] acc = Nothing
17331750 find n (PImp _ _ _ n' t : gs) acc
17341751 | n == n' = Just (t, reverse acc ++ gs)