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

Map function with a variable under walkDirRec caused a compile error #12375

Open
hokamoto opened this issue Oct 7, 2019 · 3 comments
Open

Map function with a variable under walkDirRec caused a compile error #12375

hokamoto opened this issue Oct 7, 2019 · 3 comments

Comments

@hokamoto
Copy link
Contributor

hokamoto commented Oct 7, 2019

Using a map function with a variable under walkDirRec iterator caused a compile error.

Example

The below snippet itself does not make sense because I made up it for reproducing the problem with minimum code. I came across the problem during coding a real application.

import os, sequtils, sequtils, sugar

for file in walkDirRec("./"):
  let multiplier = 5
  echo(toSeq(1..4).map(x => x * multiplier))

Current Output

Error: execution of an external compiler program 'clang -c  -w  -I/Users/hokamoto/.choosenim/toolchains/nim-1.0.0/lib -I/Users/hokamoto/NimProjects/video_thumbnail -o /Users/hokamoto/.cache/nim/a_d/a.nim.c.o /Users/hokamoto/.cache/nim/a_d/a.nim.c' failed with exit code: 1

/Users/hokamoto/.cache/nim/a_d/a.nim.c:727:45: error: use of undeclared identifier 'multiplier__oOhn9b9auJ3LN3lvBg5aNedw_2'; did you mean 'multiplier__oOhn9b9auJ3LN3lvBg5aNedw_3'?
        TM__R8RUzYq41iOx0I9bZH5Nyrw_17 = mulInt(x, multiplier__oOhn9b9auJ3LN3lvBg5aNedw_2);
                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                   multiplier__oOhn9b9auJ3LN3lvBg5aNedw_3
/Users/hokamoto/.cache/nim/a_d/a.nim.c:326:4: note: 'multiplier__oOhn9b9auJ3LN3lvBg5aNedw_3' declared here
NI multiplier__oOhn9b9auJ3LN3lvBg5aNedw_3;
   ^
1 error generated.

Expected Output

@[5, 10, 15, 20]

Possible Solution

I found the error did not occur when not using variable or not under walkDirRec.

Work (Not using a variable)

import os, sequtils, sequtils, sugar

for file in walkDirRec("./"):
  echo(toSeq(1..4).map(x => x * 5))

Work (Not under walkDirRec)

import os, sequtils, sequtils, sugar

let multiplier = 5
echo(toSeq(1..4).map(x => x * multiplier))

Additional Information

$ nim -v
Nim Compiler Version 1.0.0 [MacOSX: amd64]
Compiled at 2019-09-23
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: f7a8fc46c0012033917582eb740dc0343c093e35
active boot switches: -d:release
@narimiran
Copy link
Member

A similar example, but using mapIt, works:

import os, sequtils, sequtils, sugar

for file in walkDirRec("./"):
  let multiplier = 5
  echo(toSeq(1..4).mapIt(it * multiplier))

@hokamoto
Copy link
Contributor Author

hokamoto commented Oct 7, 2019

Thanks. mapIt works for me!
But do you know why map caused the compile error?

@hokamoto
Copy link
Contributor Author

hokamoto commented Aug 8, 2022

This issue has not been fixed on v1.6.6.

% nim -v
Nim Compiler Version 1.6.6 [MacOSX: amd64]
Compiled at 2022-07-01
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release

% nim c issue12375.nim
Hint: used config file '/Users/hokamoto/.choosenim/toolchains/nim-1.6.6/config/nim.cfg' [Conf]
Hint: used config file '/Users/hokamoto/.choosenim/toolchains/nim-1.6.6/config/config.nims' [Conf]
.......................................................................................
/Users/hokamoto/issue12375.nim(1, 22) Hint: duplicate import of 'sequtils'; previous import here: /Users/hokamoto/issue12375.nim(1, 12) [DuplicateModuleImport]
..
CC: stdlib_digitsutils.nim
CC: stdlib_assertions.nim
CC: stdlib_dollars.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: stdlib_pathnorm.nim
CC: stdlib_posix.nim
CC: stdlib_times.nim
CC: stdlib_os.nim
CC: issue12375.nim
/Users/hokamoto/.cache/nim/issue12375_d/@missue12375.nim.c:633:19: error: use of undeclared identifier 'multiplier__issue4950515553_6'; did you mean 'multiplier__issue4950515553_369'?
        if (nimMulInt(x, multiplier__issue4950515553_6, &TM__kIv9ayHDPjlWRZ8dPrg9c9cdQ_15)) { raiseOverflow(); };
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                         multiplier__issue4950515553_369
/Users/hokamoto/.choosenim/toolchains/nim-1.6.6/lib/nimbase.h:595:63: note: expanded from macro 'nimMulInt'
    #define nimMulInt(a, b, res) __builtin_smulll_overflow(a, b, (long long int*)res)
                                                              ^
/Users/hokamoto/.cache/nim/issue12375_d/@missue12375.nim.c:315:18: note: 'multiplier__issue4950515553_369' declared here
N_LIB_PRIVATE NI multiplier__issue4950515553_369;
                 ^
1 error generated.
Error: execution of an external compiler program 'clang -c  -w -ferror-limit=3   -I/Users/hokamoto/.choosenim/toolchains/nim-1.6.6/lib -I/Users/hokamoto -o /Users/hokamoto/.cache/nim/issue12375_d/@missue12375.nim.c.o /Users/hokamoto/.cache/nim/issue12375_d/@missue12375.nim.c' failed with exit code: 1

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

4 participants