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

Import statement does not follow identifier equality rules #18476

Open
Vladar4 opened this issue Jul 12, 2021 · 7 comments
Open

Import statement does not follow identifier equality rules #18476

Vladar4 opened this issue Jul 12, 2021 · 7 comments
Labels
Documentation Content Related to documentation content (not generation).

Comments

@Vladar4
Copy link
Contributor

Vladar4 commented Jul 12, 2021

The manual vaguely implies that module names should follow identifier equality rules (so, partial case-insensitivity and underscore is ignored).

A valid module name can only be a valid Nim identifier

https://nim-lang.org/docs/manual.html#modules
https://nim-lang.org/docs/manual.html#lexical-analysis-identifier-equality

But it appears that import statements treat foobar, foo_bar, or fooBar as different modules.

Example

import foobar

import foo_bar

import fooBar

# with only `foobar.nim` file present all three cases should work identically.

Current Output

Error: cannot open file: foo_bar

Expected Output

Normal compilation conforming to identifier equality.

Possible Solution

If I am mistaken about the idea that import statement should follow identifier equality rules, it would be helpful if it was reflected in the manual. Otherwise there is a bug in the import statement.

Additional Information

Original discussion: Vladar4/sdl2_nim#35 (comment)

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
git hash: 3645f5fc7ae885e22cb52b9f865edf062cfb8e59
@top-master
Copy link

The foo_bar with underscore is right to be treated differently, and any said "manual vaguely implies" should be fixed instead.

But if foobar is a Nim-package, then import foobar and import fooBar being treated differently is an issue, which should be fixed, for example, forbid packages from mixing upper-case, or simply import case-insensitive.

However, if foobar is a .nim file, then Nim should import case-sensitive even if on Windows OS, to ensure that code compiles for our macOS co-workers as well.

@c-blake
Copy link
Contributor

c-blake commented Sep 23, 2024

!nim c

import parseUtils   # works
import std/strUtils # fails
import seq_utils    # fails

Copy link
Contributor

🐧 Linux bisect by @c-blake (contributor)
devel 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:15
  • Finished 2024-09-23T11:22:15
  • Duration now

AST

stable 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:18
  • Finished 2024-09-23T11:22:18
  • Duration now

AST

2.0.8 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:18
  • Finished 2024-09-23T11:22:18
  • Duration now

AST

2.0.0 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:21
  • Finished 2024-09-23T11:22:21
  • Duration now

AST

1.6.20 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:23
  • Finished 2024-09-23T11:22:23
  • Duration now

AST

1.4.8 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:25
  • Finished 2024-09-23T11:22:25
  • Duration now

AST

1.2.18 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:27
  • Finished 2024-09-23T11:22:27
  • Duration now

AST

1.0.10 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:22:29
  • Finished 2024-09-23T11:22:29
  • Duration now

AST

Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-09-23T11:21:48Z
  • Comments 2
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 16 mins bisecting 8 commits at 0 commits per second

@c-blake
Copy link
Contributor

c-blake commented Sep 23, 2024

!nim c

import seq_utils

Repeated but simplified just to show the non-std/-qualified import with style variation also fails on all hot-loadable test Nim versions.

Copy link
Contributor

🐧 Linux bisect by @c-blake (contributor)
devel 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:26
  • Finished 2024-09-23T11:26:26
  • Duration

AST

stable 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:30
  • Finished 2024-09-23T11:26:30
  • Duration now

AST

2.0.8 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:30
  • Finished 2024-09-23T11:26:30
  • Duration now

AST

2.0.0 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:34
  • Finished 2024-09-23T11:26:34
  • Duration now

AST

1.6.20 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:37
  • Finished 2024-09-23T11:26:37
  • Duration now

AST

1.4.8 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:40
  • Finished 2024-09-23T11:26:40
  • Duration now

AST

1.2.18 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:42
  • Finished 2024-09-23T11:26:42
  • Duration now

AST

1.0.10 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-09-23T11:26:43
  • Finished 2024-09-23T11:26:43
  • Duration now

AST

Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-09-23T11:25:54Z
  • Comments 4
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 20 mins bisecting 8 commits at 0 commits per second

@Araq Araq added the Documentation Content Related to documentation content (not generation). label Sep 23, 2024
@Araq
Copy link
Member

Araq commented Sep 23, 2024

Only needs to be documented, Nim first tries the name as written and then in all lowercase.

@c-blake
Copy link
Contributor

c-blake commented Sep 23, 2024

It seems the std/ package qualification also changes things...

c-blake added a commit to c-blake/kslog that referenced this issue Sep 23, 2024
sub-words as Nim behaves oddly there ( evidently intentionally as per
nim-lang/Nim#18476 ).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Content Related to documentation content (not generation).
Projects
None yet
Development

No branches or pull requests

4 participants