test: symbol clash on private import of same def (#10915)

This PR adds a test for depending on two packages which privately import
modules that define the same Lean definition. It verifies the current
behavior of a symbol clash. This behavior will be fixed later this
quarter.
This commit is contained in:
Mac Malone 2025-10-22 23:42:52 -04:00 committed by GitHub
parent 69e1eae480
commit 291d238ec4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 99 additions and 0 deletions

1
tests/pkg/def_clash/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
produced.out

View file

@ -0,0 +1,3 @@
module
import FooA
import FooB

View file

@ -0,0 +1,7 @@
module
import UseA
import UseB
def main : IO Unit := do
IO.println useA
IO.println useB

2
tests/pkg/def_clash/clean.sh Executable file
View file

@ -0,0 +1,2 @@
rm -rf lake-manifest.json .lake/build produced.out
rm -rf deps/fooA/.lake/build deps/fooB/.lake/build deps/useA/.lake/build deps/useB/.lake/build

View file

@ -0,0 +1,3 @@
module
public def foo : String := "fooA"

View file

@ -0,0 +1,5 @@
name = "fooA"
[[lean_lib]]
name = "FooA"
leanOptions.experimental.module = true

View file

@ -0,0 +1,3 @@
module
public def foo : String := "fooB"

View file

@ -0,0 +1,5 @@
name = "fooB"
[[lean_lib]]
name = "FooB"
leanOptions.experimental.module = true

View file

@ -0,0 +1,4 @@
module
import FooA
public def useA : String := foo

View file

@ -0,0 +1,9 @@
name = "useA"
[[lean_lib]]
name = "UseA"
leanOptions.experimental.module = true
[[require]]
name = "fooA"
path = "../fooA"

View file

@ -0,0 +1,4 @@
module
import FooB
public def useB : String := foo

View file

@ -0,0 +1,9 @@
name = "useB"
[[lean_lib]]
name = "UseB"
leanOptions.experimental.module = true
[[require]]
name = "fooB"
path = "../fooB"

View file

@ -0,0 +1,17 @@
name = "test"
[[lean_lib]]
name = "TestFoo"
leanOptions.experimental.module = true
[[lean_exe]]
name = "TestUse"
leanOptions.experimental.module = true
[[require]]
name = "useA"
path = "deps/useA"
[[require]]
name = "useB"
path = "deps/useB"

27
tests/pkg/def_clash/test.sh Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Tests the behavior of transitively importing multiple modules
# that define the same symbol.
# Currently, if two packages define the same Lean symbol (e.g., `foo`)
# they cannot be in the same transitive import graph, even if the no module
# can see both instances of the symbol.
# In the example in this directory, `fooA` and `fooB` both define `foo`.
# `useA` privately imports and uses `fooA`, and `useB` private imports and uses
# `fooB`. When `TestUse` imports `useA` and `useB`, the linker will complain
# even though the Lean file does not see both `foo` definitions.
# See also https://github.com/leanprover/lean4/issues/222
source ../../lake/tests/common.sh
./clean.sh
# Test the behavior when multiple copies of the same definition (`foo`)
# are seen by Lean (e.g., via importing two modules which define them).
test_err "environment already contains 'foo'" build TestFoo
# Test the behavior when multiple copies of the same definition (`foo`) exist
# but are not visible to any one module: a symbol clash between the two `foo`s.
test_err "l_foo" build TestUse