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

The when nimvm statement fails to compile when in a file called nimvm.nim #23606

Open
eanyanwu opened this issue May 14, 2024 · 4 comments
Open

Comments

@eanyanwu
Copy link

eanyanwu commented May 14, 2024

Description

I am familiarizing myself with the language by going through the manual.
I am creating seperate nim files to test some of the stuff in the manual.

This snippet from the manual fails to compile when it is in a file called nimvm.nim

# in a file called nimvm.nim
proc someProcThatMayRunInCompileTime(): bool =
  when nimvm:
    result = true
  else:
    result = false

The following errors is printed at the terminal when run with nim c -r nimvm.nim:

/home/eze/crafts/learnnim/nimvm.nim(2, 8) Error: expression 'nimvm' has no type (or is ambiguous)

It could very well be that this is "expected" because of something I have not yet hit in the manual. I thought I would flag it anyways.

Nim Version

Nim Compiler Version 2.0.4 [Linux: amd64]
Compiled at 2024-03-28
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b47747d
active boot switches: -d:release

Current Output

Hint: used config file '/home/eze/.choosenim/toolchains/nim-2.0.4/config/nim.cfg' [Conf]
Hint: used config file '/home/eze/.choosenim/toolchains/nim-2.0.4/config/config.nims' [Conf]
......................................................................
/home/eze/crafts/learnnim/nimvm.nim(2, 8) Error: expression 'nimvm' has no type (or is ambiguous)

Expected Output

Nothing

Possible Solution

I'm a newbie so I'm afraid I don't have any idea :)

Additional Information

Thank you for your work!

@eanyanwu
Copy link
Author

eanyanwu commented May 14, 2024

Ah ... i think this is because a file is a module and the module's name can be accessed from within itself? This could probably be closed. I could have asked this in the forum. I suspect this is normal behavior.

@eanyanwu
Copy link
Author

Re-opening because I got through the manual and still do not understand why this doesn't work... So i think it might be a bug

@eanyanwu eanyanwu reopened this May 14, 2024
@metagn
Copy link
Collaborator

metagn commented May 14, 2024

Another module symbol bug, coincidentally might work in devel now with #23597

@metagn
Copy link
Collaborator

metagn commented May 15, 2024

Quirk of when, it directly calls lookUp to check if nimvm is system.nimvm. We could either hardcode the identifier "nimvm" to invoke when nimvm (and working around it with when (nimvm):) or allow something like when system.nimvm which currently doesn't compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants