Skip to content
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

Allow using block labels as qualifiers #498

Open
metagn opened this issue Nov 29, 2022 · 0 comments
Open

Allow using block labels as qualifiers #498

metagn opened this issue Nov 29, 2022 · 0 comments

Comments

@metagn
Copy link
Contributor

metagn commented Nov 29, 2022

Abstract

Allow using block labels as qualifiers for symbols defined in them, i.e. block1.proc1.

Motivation

In situations like this, there is no way to disambiguate them (nim-lang/Nim#18785):

proc foo() = echo 1
block:
  proc foo() = echo 2
  foo()
  let x = foo

If we add a label to the block, we could qualify each proc by using the module name for the first proc, and the block label for the second proc.

Description

Not super sure how block labels are implemented, but I think the best way to implement this would be by setting the owner of the defined symbol to the block label symbol, if this is not the case already.

Not sure if module1.proc1 works for symbols defined in blocks. If so, it should be made so they shouldn't.

Code Examples

proc foo() = echo 1
block fooBlock:
  proc foo() = echo 2
  foo()
  modulename.foo()
  fooBlock.foo()
  let x = modulename.foo
  let y = fooBlock.foo

Backwards Compatibility

Macros that extract the modules of symbols using the owner field might have to account for this situation. i.e.

proc findModule(sym: NimNode): NimNode =
  if sym.owner.kind == nskLabel: findModule(sym.owner)
  else: sym.owner

Although they are probably already implemented like this, which should not be affected:

proc findModule(sym: NimNode): NimNode =
  result = sym
  while result.kind != nskModule:
    result = result.owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant