lean4-htt/tests/lean/private.lean
Leonardo de Moura 7322345768 fix: private names
@Kha I tried to fix a few issues with private names. The new test
tries to cover them. If you have more, please create an issue.

1- Scoping. A private declaration should shadow one in a previous scope.
2- We should not be able to define the same `private` in the same
module more than once.
   ```
   private def x := 10
   private def x := "hello" -- should produce error here
   ```
3- Dot-notation should work with private declarations in the module
where they were defined.
4- The following should work
   ```
   namespace N
   private def x := 10
   end N
   #check N.x
   ```
5- The following should **not** work
   ```
   def y := 10
   private def y := "hello" -- produce error

   private def z := 10
   def z := "hello" -- produce error
   ```
   BTW, I am happy to change this behavior. I just mimicked C's
   behavior for `static`.

It is not clear whether the following should work or not.
```
    namespace N
      private def b := 10
    end N
    open N
    #check b
```
2020-04-09 16:28:21 -07:00

68 lines
990 B
Text

new_frontend
-- Issue 1
def foo := 10
def f (x : Nat) := x + x
namespace Bla
private def foo := "hello"
#check foo == "world" -- `foo` resolves to private `Bla.foo`
private def foo : Float := 1.0 -- should produce error like in other programming languages
end Bla
#check foo == 0
#check Bla.foo
-- Issue 2
namespace Boo
def boo := 100
namespace Bla
private def boo := "hello"
#check boo == "world" -- resolving to `Boo.Bla.boo` as expected
#check boo ++ "world" -- should work
end Bla
#check Bla.boo == "world"
#check boo == 100
end Boo
#check Boo.Bla.boo == "world"
#check Boo.boo == 100
/-
Should the following work?
```
namespace N
private def b := 10
end N
open N
#check b
```
-/
-- Issue 3
private def Nat.mul10 (x : Nat) := x * 10
def x := 10
#check x.mul10 -- dot-notation should work with local private declarations
-- Issue 4
def y := 10
private def y := "hello" -- produce error
private def z := 10
def z := "hello" -- produce error