@@ -442,6 +442,7 @@ elab ist info emode opts fn tm
442-- trace (show (map showHd as')) $
442-- trace (show (map showHd as')) $
443 ty <- goal
443 ty <- goal
444 case as' of
444 case as' of
445+ [] -> lift $ tfail $ NoValidAlts (map showHd as)
445 [x] -> elab' ina fc x
446 [x] -> elab' ina fc x
446 -- If there's options, try now, and if that fails, postpone
447 -- If there's options, try now, and if that fails, postpone
447 -- to later.
448 -- to later.
@@ -458,18 +459,24 @@ elab ist info emode opts fn tm
458 [x] -> elab' ina fc x
459 [x] -> elab' ina fc x
459 _ -> tryAll (zip (map (elab' ina fc) as'')
460 _ -> tryAll (zip (map (elab' ina fc) as'')
460 (map showHd as'')))
461 (map showHd as'')))
461− where showHd (PApp _ (PRef _ _ n) _) = n
462+ where showHd (PApp _ (PRef _ _ (UN l)) [_, _, arg])
463+ | l == txt "Delay" = showHd (getTm arg)
464+ showHd (PApp _ (PRef _ _ n) _) = n
462 showHd (PRef _ _ n) = n
465 showHd (PRef _ _ n) = n
463 showHd (PApp _ h _) = showHd h
466 showHd (PApp _ h _) = showHd h
464 showHd x = NErased -- We probably should do something better than this here
467 showHd x = NErased -- We probably should do something better than this here
466 doPrune as =
469 doPrune as =
467− do hnf_compute
470+ do compute
468 ty <- goal
471 ty <- goal
469− let (tc, _) = unApply ty
472+ let (tc, _) = unApply (unDelay ty)
470 env <- get_env
473 env <- get_env
471 return $ pruneByType env tc ist as
474 return $ pruneByType env tc ist as
476+ unDelay t | (P _ (UN l) _, [_, arg]) <- unApply t,
477+ l == txt "Lazy'" = unDelay arg
474 isAmbiguous (CantResolveAlts _) = delayok
481 isAmbiguous (CantResolveAlts _) = delayok
475 isAmbiguous (Elaborating _ _ e) = isAmbiguous e
482 isAmbiguous (Elaborating _ _ e) = isAmbiguous e
@@ -492,20 +499,21 @@ elab ist info emode opts fn tm
492 solveAutos ist fn False) (trySeq' deferr xs) True
499 solveAutos ist fn False) (trySeq' deferr xs) True
493 elab' ina fc (PAlternative ms TryImplicit (orig : alts)) = do
500 elab' ina fc (PAlternative ms TryImplicit (orig : alts)) = do
494 env <- get_env
501 env <- get_env
495 ty <- goal
503 ty <- goal
496 let doelab = elab' ina fc orig
504 let doelab = elab' ina fc orig
497 tryCatch doelab
505 tryCatch doelab
498 (\err ->
506 (\err ->
499 if recoverableErr err
507 if recoverableErr err
500 then -- trace ("NEED IMPLICIT! " ++ show orig ++ "\n" ++
508 then -- trace ("NEED IMPLICIT! " ++ show orig ++ "\n" ++
501− -- show alts ++ "\n" ++
509+ -- show alts ++ "\n" ++
502− -- showQuick err) $
510+ -- showQuick err) $
503 -- Prune the coercions so that only the ones
511 -- Prune the coercions so that only the ones
504 -- with the right type to fix the error will be tried!
512 -- with the right type to fix the error will be tried!
505 case pruneAlts err alts env of
513 case pruneAlts err alts env of
506 [] -> lift $ tfail err
514 [] -> lift $ tfail err
507− alts' ->
515+ alts' -> do
508− try' (elab' ina fc (PAlternative [] (ExactlyOne False) alts'))
516+ try' (elab' ina fc (PAlternative ms (ExactlyOne False) alts'))
509 (lift $ tfail err) -- take error from original if all fail
517 (lift $ tfail err) -- take error from original if all fail
511 else lift $ tfail err)
519 else lift $ tfail err)
@@ -529,8 +537,8 @@ elab ist info emode opts fn tm
529 _ -> filter isLend alts -- special case hack for 'Borrowed'
537 _ -> filter isLend alts -- special case hack for 'Borrowed'
530 pruneAlts (ElaboratingArg _ _ _ e) alts env = pruneAlts e alts env
538 pruneAlts (ElaboratingArg _ _ _ e) alts env = pruneAlts e alts env
531 pruneAlts (At _ e) alts env = pruneAlts e alts env
539 pruneAlts (At _ e) alts env = pruneAlts e alts env
532− pruneAlts (NoValidAlts _) alts env = alts
540+ pruneAlts (NoValidAlts as) alts env = alts
533− pruneAlts _ alts _ = filter isLend alts
541+ pruneAlts err alts _ = filter isLend alts
535 hasArg n env ap | isLend ap = True -- special case hack for 'Borrowed'
543 hasArg n env ap | isLend ap = True -- special case hack for 'Borrowed'
536 hasArg n env (PApp _ (PRef _ _ a) _)
544 hasArg n env (PApp _ (PRef _ _ a) _)
@@ -538,7 +546,8 @@ elab ist info emode opts fn tm
538 Just ty -> let args = map snd (getArgTys (normalise (tt_ctxt ist) env ty)) in
546 Just ty -> let args = map snd (getArgTys (normalise (tt_ctxt ist) env ty)) in
539 any (fnIs n) args
547 any (fnIs n) args
540 Nothing -> False
548 Nothing -> False
541− hasArg n _ _ = False
549+ hasArg n env (PAlternative _ _ as) = any (hasArg n env) as
550+ hasArg n _ tm = False
543 isLend (PApp _ (PRef _ _ l) _) = l == sNS (sUN "lend") ["Ownership"]
552 isLend (PApp _ (PRef _ _ l) _) = l == sNS (sUN "lend") ["Ownership"]
544 isLend _ = False
553 isLend _ = False
@@ -1376,7 +1385,7 @@ elab ist info emode opts fn tm
1376 notImplicitable (PRef _ _ n)
1385 notImplicitable (PRef _ _ n)
1377 | [opts] <- lookupCtxt n (idris_flags ist)
1386 | [opts] <- lookupCtxt n (idris_flags ist)
1378 = NoImplicit `elem` opts
1387 = NoImplicit `elem` opts
1379− notImplicitable (PAlternative _ (ExactlyOne _) as) = any notImplicitable as
1388+ notImplicitable (PAlternative _ _ as) = any notImplicitable as
1380 -- case is tricky enough without implicit coercions! If they are needed,
1389 -- case is tricky enough without implicit coercions! If they are needed,
1381 -- they can go in the branches separately.
1390 -- they can go in the branches separately.
1382 notImplicitable (PCase _ _ _) = True
1391 notImplicitable (PCase _ _ _) = True
@@ -1420,9 +1429,11 @@ elab ist info emode opts fn tm
1420 (PCoerced tm, _) -> tm
1429 (PCoerced tm, _) -> tm
1421 (_, []) -> t
1430 (_, []) -> t
1422 (_, cs) -> PAlternative [] TryImplicit
1431 (_, cs) -> PAlternative [] TryImplicit
1423− (t : map (mkCoerce env t) cs)
1432+ (t : map (mkCoerce env t) cs)
1424 return t'
1433 return t'
1435+ mkCoerce env (PAlternative ms aty tms) n
1436+ = PAlternative ms aty (map (\t -> mkCoerce env t n) tms)
1426 mkCoerce env t n = let fc = maybe (fileFC "Coercion") id (highestFC t) in
1437 mkCoerce env t n = let fc = maybe (fileFC "Coercion") id (highestFC t) in
1427 addImplBound ist (map fst env)
1438 addImplBound ist (map fst env)
1428 (PApp fc (PRef fc [] n) [pexp (PCoerced t)])
1439 (PApp fc (PRef fc [] n) [pexp (PCoerced t)])
@@ -1520,6 +1531,8 @@ pruneByType env t c as
1520 n `elem` map fst env = Just t
1531 n `elem` map fst env = Just t
1521 | otherwise = locallyBound ts
1532 | otherwise = locallyBound ts
1522 getName (PRef _ _ n) = Just n
1533 getName (PRef _ _ n) = Just n
1534+ getName (PApp _ (PRef _ _ (UN l)) [_, _, arg]) -- ignore Delays
1535+ | l == txt "Delay" = getName (getTm arg)
1523 getName (PApp _ f _) = getName f
1536 getName (PApp _ f _) = getName f
1524 getName (PHidden t) = getName t
1537 getName (PHidden t) = getName t
1525 getName _ = Nothing
1538 getName _ = Nothing
@@ -1528,18 +1541,20 @@ pruneByType env t c as
1528pruneByType env (P _ n _) ist as
1541pruneByType env (P _ n _) ist as
1529-- if the goal type is polymorphic, keep everything
1542-- if the goal type is polymorphic, keep everything
1530 | Nothing <- lookupTyExact n ctxt = as
1543 | Nothing <- lookupTyExact n ctxt = as
1544+-- if the goal type is a ?metavariable, keep everything
1545+ | Just _ <- lookup n (idris_metavars ist) = as
1531 | otherwise
1546 | otherwise
1532 = let asV = filter (headIs True n) as
1547 = let asV = filter (headIs True n) as
1533 as' = filter (headIs False n) as in
1548 as' = filter (headIs False n) as in
1534 case as' of
1549 case as' of
1537− _ -> asV
1550+ [] -> asV
1538 _ -> as'
1551 _ -> as'
1540 ctxt = tt_ctxt ist
1553 ctxt = tt_ctxt ist
1542 headIs var f (PRef _ _ f') = typeHead var f f'
1555 headIs var f (PRef _ _ f') = typeHead var f f'
1556+ headIs var f (PApp _ (PRef _ _ (UN l)) [_, _, arg])
1557+ | l == txt "Delay" = headIs var f (getTm arg)
1543 headIs var f (PApp _ (PRef _ _ f') _) = typeHead var f f'
1558 headIs var f (PApp _ (PRef _ _ f') _) = typeHead var f f'
1544 headIs var f (PApp _ f' _) = headIs var f f'
1559 headIs var f (PApp _ f' _) = headIs var f f'
1545 headIs var f (PPi _ _ _ _ sc) = headIs var f sc
1560 headIs var f (PPi _ _ _ _ sc) = headIs var f sc