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.24k stars 1.46k forks source link

Typed macro removes `std /` in imports #19904

Open HugoGranstrom opened 2 years ago

HugoGranstrom commented 2 years ago

When passing an import using the syntax:

import std / [jsonutils]
import karax / [kbase]

to a typed macro the first part of the import is removed resulting in this:

import jsonutils
import kbase

which gives an error like:

Error: cannot open file: jsonutils

Note: If you replace typed with untyped it works.

Example


import macros

macro identity(body: typed) = echo body.repr result = body

identity: import std/[jsonutils]


### Current Output

import jsonutils

C:\Users\hugog\code\nim\nimib\a.nim(7, 1) template/generic instantiation of identity from here C:\Users\hugog\code\nim\nimib\a.nim(8, 13) Error: cannot open file: jsonutils


### Expected Output

import std / [jsonutils]


### Possible Solution

* No idea sadly

### Additional Information
Have tried it on version 1.6.6, 1.6.0, 1.4.8, 1.4.0, and the latest devel. All give the same error. 

$ nim -v Nim Compiler Version 1.7.1 [Windows: amd64] Compiled at 2022-06-17 Copyright (c) 2006-2022 by Andreas Rumpf

active boot switches: -d:release

bung87 commented 1 year ago

weird, I just tried , if you change the module to other like jsonutils -> cstrutils , it will not error you.

HugoGranstrom commented 1 year ago

@bung87

weird, I just tried , if you change the module to other like jsonutils -> cstrutils , it will not error you.

It's because some modules in the stdlib requires the std / prefix while others don't. jsonutils is one which requires it while cstrutils doesn't. Try this code for example:

import jsonutils
# Error: cannot open file: jsonutils

While this one works:

import cstrutils