Skip to content

Commit

Permalink
fix: bad 'unknown package' error message (leanprover#4424)
Browse files Browse the repository at this point in the history
This message is older than corresponding, better checks in Lake and
vscode-lean4

Fixes leanprover#4419

---------

Co-authored-by: Mac Malone <[email protected]>
  • Loading branch information
Kha and tydeu authored Jun 13, 2024
1 parent 7b971b9 commit 749bf9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions src/Lean/Util/Path.lean
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,10 @@ partial def findOLean (mod : Name) : IO FilePath := do
return fname
else
let pkg := FilePath.mk <| mod.getRoot.toString (escape := false)
let mut msg := s!"unknown package '{pkg}'"
let rec maybeThisOne dir := do
if ← (dir / pkg).isDir then
return some s!"\nYou might need to open '{dir}' as a workspace in your editor"
if let some dir := dir.parent then
maybeThisOne dir
else
return none
if let some msg' ← maybeThisOne (← IO.currentDir) then
msg := msg ++ msg'
let mut msg := s!"unknown module prefix '{pkg}'
No directory '{pkg}' or file '{pkg}.lean' in the search path entries:
{"\n".intercalate <| sp.map (·.toString)}"
throw <| IO.userError msg

/-- Infer module name of source file name. -/
Expand Down
2 changes: 1 addition & 1 deletion src/lake/tests/badImport/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LAKE=${LAKE:-../../.lake/build/bin/lake}
# https://github.com/leanprover/lean4/issues/3809

# Test importing a nmissing module from outside the workspace
($LAKE build +X 2>&1 && exit 1 || true) | grep --color -F "X.lean:1:0: unknown package 'Y'"
($LAKE build +X 2>&1 && exit 1 || true) | grep --color -F "X.lean:1:0: unknown module prefix 'Y'"
$LAKE setup-file ./X.lean Y # Lake ignores the file (the server will error)
# Test importing onself
($LAKE build +Lib.A 2>&1 && exit 1 || true) | grep --color -F "A.lean: module imports itself"
Expand Down

0 comments on commit 749bf9c

Please sign in to comment.