As far as I understand this code should fail, as now should be accessible only as nt.now, but it compiles, is it a bug?
import times as nt
echo now()
For fully qualified import we used
from times import nil
But indeed with recent Nim that works with renamed module also:
from times as nt import nil
echo nt.now()
Without nt prefix it will not compile as desired.
Thanks!
Although I would say it would be better to change how it works and not import it into the scope. It's really counterintuitive. Usually the whole point to import module with specific name is to avoid conflicts in the current file, and with the current behaviour it fails at that.
with the current behaviour it fails at that
Please give simple short example for fail, here or maybe better in github issue tracker.
I didn't phrased it properly, it not fails, but not helps to achieve what you want, avoid polluting current scope with the stuff from the imported module.
Example (it works, but it pollutes the current scope with the std/times stuff)
import std/times as nt
type
Time = object
time: string
proc now*(_: typedesc[Time]): Time =
Time(time: nt.format(nt.utc(nt.now()), "yyyy-MM-dd"))
echo Time.now