Add "intro" to LSP, improve error locations

This commit is contained in:
2026-02-23 13:16:06 -08:00
parent 673c79b786
commit 3cc3801f4d
4 changed files with 79 additions and 21 deletions

View File

@@ -999,13 +999,12 @@ mkPat (tm, icit) = do
pure $ PatCon (getFC tm) icit name bpat Nothing
-- This fires when a global is shadowed by a pattern var
-- Just _ => error (getFC tm) "\{show nm} is not a data constructor"
_ => case b of
-- TODO maybe check case?
Nil =>
if isUpperName nm
_ => if isUpperName nm
-- This is not entirely accurate - it could be a function def
then error (getFC tm) "\{nm} not in scope"
else pure $ PatVar fc icit nm
_ => error (getFC tm) "patvar applied to args"
else case b of
Nil => pure $ PatVar fc icit nm
_ => error (getFC tm) "patvar applied to args"
((RImplicit fc), Nil) => pure $ PatWild fc icit
((RImplicit fc), _) => error fc "implicit pat can't be applied to arguments"
((RLit fc lit), Nil) => pure $ PatLit fc lit
@@ -1486,9 +1485,10 @@ check ctx tm ty = do
pure $ Lam fc nm' icit rig sc
else
error fc "Icity issue checking \{show t} at \{show ty}"
(t@(RLam _ (BI fc nm icit quant) tm), ty) => do
(t@(RLam fc (BI _ nm icit quant) tm), ty) => do
pty <- prvalCtx ty
error fc "Expected \{pty}, got pi type"
-- TODO I'm hitting this with an unsolved meta
error fc "Expected \{pty}, got a function"
(RLet fc nm ty v sc, rty) => do
ty' <- check ctx ty (VU emptyFC)
@@ -1513,7 +1513,6 @@ check ctx tm ty = do
pure $ Lam (getFC tm) nm' Implicit rig sc
(tm, ty@(VPi fc nm' Auto rig a b)) => do
let names = map fst ctx.types
debug $ \ _ => "XXX edge case add auto lambda {\{nm'} : \{show a}} to \{show tm} "
let var = VVar fc (length' ctx.env) Lin
ty' <- b $$ var

View File

@@ -311,14 +311,16 @@ pLamArg = impArg <|> autoArg <|> expArg
lamExpr : Parser Raw
lamExpr = do
pos <- getPos
keyword "\\" <|> keyword "λ"
args <- some $ addPos pLamArg
keyword "=>"
scope <- typeExpr
pure $ foldr mkLam scope args
(fc, args, scope) <- withFC $ do
keyword "\\" <|> keyword "λ"
args <- some $ addPos pLamArg
keyword "=>"
scope <- typeExpr
pure (args, scope)
pure $ foldr (mkLam fc) scope args
where
mkLam : FC × Icit × Name × Maybe Raw Raw Raw
mkLam (fc, icit, name, ty) sc = RLam fc (BI fc name icit Many) sc
mkLam : FC FC × Icit × Name × Maybe Raw Raw Raw
mkLam fc (nfc, icit, name, ty) sc = RLam fc (BI nfc name icit Many) sc
caseAlt : Parser RCaseAlt
@@ -566,10 +568,11 @@ parseDef = do
nm <- getName t
Just _ <- optional $ keyword "="
-- impossible clause
-- TODO we should require outdent
| Nothing => pure $ FunDef fc nm ((t,Nothing) :: Nil)
-- TODO could we recover and keep the LHS?
body <- typeExpr
wfc <- getPos
w <- optional $ do
(wfc, w) <- withFC $ optional $ do
keyword "where"
startBlock $ manySame $ (parseSig <|> parseDef)
let body = maybe body (\ decls => RWhere wfc decls body) w