Skip to content

Commit 857ba0a

Browse files
committed
fix: support non-identifier library names
1 parent ad77e7e commit 857ba0a

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

src/Lean/Util/Path.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace SearchPath
3333
`ext` (`lean` or `olean`) corresponding to `mod`. Otherwise, return `none`. Does
3434
not check whether the returned path exists. -/
3535
def findWithExt (sp : SearchPath) (ext : String) (mod : Name) : IO (Option FilePath) := do
36-
let pkg := mod.getRoot.toString
36+
let pkg := mod.getRoot.toString (escape := false)
3737
let root? ← sp.findM? fun p =>
3838
(p / pkg).isDir <||> ((p / pkg).withExtension ext).pathExists
3939
return root?.map (modToFilePath · mod ext)
@@ -94,7 +94,7 @@ partial def findOLean (mod : Name) : IO FilePath := do
9494
if let some fname ← sp.findWithExt "olean" mod then
9595
return fname
9696
else
97-
let pkg := FilePath.mk mod.getRoot.toString
97+
let pkg := FilePath.mk <| mod.getRoot.toString (escape := false)
9898
let mut msg := s!"unknown package '{pkg}'"
9999
let rec maybeThisOne dir := do
100100
if ← (dir / pkg).isDir then

src/lake/Lake/CLI/Init.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def initPkg (dir : FilePath) (name : String) (tmp : InitTemplate) (env : Lake.En
169169
if tmp = .exe || rootExists then
170170
pure (root, rootFile, rootExists)
171171
else
172-
let root := toUpperCamelCase (toUpperCamelCaseString name |>.toName)
172+
let root := toUpperCamelCase pkgName
173173
let rootFile := Lean.modToFilePath dir root "lean"
174174
pure (root, rootFile, ← rootFile.pathExists)
175175

src/lake/tests/init/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/hello_world
33
/hello-world
44
/lean-data
5+
/123-hello
56
/meta

src/lake/tests/init/clean.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ rm -rf Hello
22
rm -rf hello-world
33
rm -rf hello_world
44
rm -rf lean-data
5+
rm -rf 123-hello
56
rm -rf meta

src/lake/tests/init/test.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ $LAKE -d hello-world build
2424
hello-world/.lake/build/bin/hello-world
2525
test -f hello-world/Hello/World/Basic.lean
2626

27-
# Test creating packages with a `-` (i.e., a non-Lean name)
27+
# Test creating packages with a `-` (i.e., a non-identifier package name)
2828
# https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/lake.20new.20lean-data
2929

3030
$LAKE new lean-data
3131
$LAKE -d lean-data build
3232
lean-data/.lake/build/bin/lean-data
3333

34+
# Test creating packages starting with digits (i.e., a non-identifier library name)
35+
# https://github.com/leanprover/lean4/issues/2865
36+
37+
$LAKE new 123-hello
38+
$LAKE -d 123-hello build
39+
123-hello/.lake/build/bin/123-hello
40+
3441
# Test creating packages with keyword names
3542
# https://github.com/leanprover/lake/issues/128
3643

0 commit comments

Comments
 (0)