nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.63k stars 1.47k forks source link

Import statement does not follow identifier equality rules #18476

Open Vladar4 opened 3 years ago

Vladar4 commented 3 years ago

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: https://github.com/Vladar4/sdl2_nim/issues/35#issuecomment-835403915

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
git hash: 3645f5fc7ae885e22cb52b9f865edf062cfb8e59
top-master commented 7 months ago

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 commented 2 months ago

!nim c

import parseUtils   # works
import std/strUtils # fails
import seq_utils    # fails
github-actions[bot] commented 2 months ago
:penguin: Linux bisect by @c-blake (contributor)
devel :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
stable :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
2.0.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
2.0.0 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.6.20 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.4.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.2.18 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.0.10 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
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

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

c-blake commented 2 months ago

!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.

github-actions[bot] commented 2 months ago
:penguin: Linux bisect by @c-blake (contributor)
devel :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
stable :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
2.0.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
2.0.0 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.6.20 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.4.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.2.18 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
1.0.10 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

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

AST

```nim ```
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

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

Araq commented 2 months ago

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

c-blake commented 2 months ago

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