-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using open
or export
does not make names accessible for extended field notation (dot notation)
#3031
Comments
I would love this feature, it would be a way to avoid the name-clash-inducing practice of defining functions outside the project namespace so that you get dot notation on types you don't own. (PS: I would describe this as a feature request / RFC, not a bug.) |
I think this is an RFC :) . It is a sensible enhancement suggestion but it is not an accidental oversight in the implementation. |
I should also mention a much older proposal of allowing any top-level name in scope as a target for extended field notation. This is especially interesting for typeclasses where it would allow us to use |
This definition was clearly meant to be in the `List` namespace, but it is also in a `namespace Lean` so it ended up as `Lean.List.toSMap` instead of `List.toSMap`. It would be nice if #3031 made this unnecessary, but for now this seems to be the convention. I noticed this because of another side effect: it defines `Lean.List` as a namespace, which means that ```lean import Std namespace Lean open List #check [1] <+ [2] ``` does not work as expected, it opens the `Lean.List` namespace instead of the `List` namespace. Should there be a regression test to ensure that the `Lean.List` namespace (and maybe others) are not accidentally created? (Unfortunately this puts a bit of a damper on #3031.)
This PR changes how generalized field notation ("dot notation") resolves the name of the function, adds a feature where terms such as `x.toString` can resolve as `toString x` as a last resort, and modifies the `Function` dot notation to always use the first explicit argument rather than the first function argument. The new rule is that if `x : S`, then `x.f` resolves the name `S.f` relative to the root namespace (hence it now responds to `export` and `open). Breaking change: aliases now resolve differently. Before, if `x : S`, and `S.f` is an alias for `S'.f`, then `x.f` would use `S'.f` and look for an argument of type `S'`. Now, it looks for an argument of type `S`, which is more generally useful behavior. Code making use of the old behavior should consider defining `S` or `S'` in terms of the other, since dot notation can unfold definitions during resolution. This also fixes a bug in explicit field notation (`@x.f`) where `x` could be passed as the wrong argument. Closes leanprover#3031
#6189 implements this along with @Kha's suggestion. New rule: given Additionally, as a last resort, after all attempts of unfolding (This is all still pending seeing if building mathlib uncovers any problems with this scheme! Edit: Mathlib only needed a few lines changed. |
This PR changes how generalized field notation ("dot notation") resolves the function. The new resolution rule is that if `x : S`, then `x.f` resolves the name `S.f` relative to the root namespace (hence it now affected by `export` and `open`). Breaking change: aliases now resolve differently. Before, if `x : S`, and if `S.f` is an alias for `S'.f`, then `x.f` would use `S'.f` and look for an argument of type `S'`. Now, it looks for an argument of type `S`, which is more generally useful behavior. Code making use of the old behavior should consider defining `S` or `S'` in terms of the other, since dot notation can unfold definitions during resolution. This also fixes a bug in explicit-mode generalized field notation (`@x.f`) where `x` could be passed as the wrong argument. This was not a bug for explicit-mode structure projections. Closes #3031. Addresses the `Function` namespace issue in #1629.
Description
If you try to use
open
orexport
to import names to use for dot notation, it does not work. Confusingly, you can haveString.a "x"
succeed but"x".a
fail.Context
Zulip thread where this was brought up, during an Advent of Code problem.
Steps to Reproduce
Observe that
"x".a
produces an error in the followingExpected behavior: The second and third
#eval
s have the same interpretation as the first.Actual behavior: Only the first succeeds. The second
#eval
(when the name is justopen
) doesn't seeString.a
at all, and the third#eval
(when the name isexport
ed) it sees it but then fails to process it correctly.Versions
MacOS arm64
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: