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.55k stars 1.47k forks source link

An exported converter, is silently exported by intermediate module #22416

Open enthus1ast opened 1 year ago

enthus1ast commented 1 year ago

Description

An exported converter causes issues later in the import chain. Even if the module a is not exported by b.nim it is still causing issues in c.nim

a.nim

converter toInt*(x: uint8): int = int(x)

proc `$`*(x: uint8): string {.raises: [].} =
  result.addInt(int(x))

b.nim

import a

c.nim

import b
echo 10'u8

Also see:

https://github.com/Vladar4/sdl2_nim/issues/38 https://forum.nim-lang.org/t/8646#56246

Nim Version

Nim Compiler Version 2.0.0 [Linux: amd64] Compiled at 2023-08-01 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: a488067a4130f029000be4550a0fb1b39e0e9e7c active boot switches: -d:release

Current Output

nim c -r c.nim 
Hint: used config file '/home/david/.choosenim/toolchains/nim-2.0.0/config/nim.cfg' [Conf]
Hint: used config file '/home/david/.choosenim/toolchains/nim-2.0.0/config/config.nims' [Conf]
Hint: used config file '/home/david/projects/nimPlayground/config.nims' [Conf]
........................................................................
/home/david/projects/nimPlayground/conv/b.nim(1, 8) Warning: imported and not used: 'a' [UnusedImport]
/home/david/projects/nimPlayground/conv/c.nim(2, 1) Error: type mismatch
Expression: echo 10'u8
  [1] 10'u8: uint8

Expected one of (first mismatch at [position]):
[1] proc echo(x: varargs[typed, `$`])

Expected Output

10

Possible Solution

No response

Additional Information

No response

awr1 commented 1 year ago

iirc converters are meant to be non-exportable. this is not mentioned in the manual but i recall some convo on IRC indicating this was the case.

Araq commented 1 year ago

Converters can be exported but the export rules are the same: A direct import makes the converter visible (and implicitly invokable) and an indirect import does not.