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

unexported type aliases in imported module visible when using newSeq #19074

Open shirleyquirk opened 3 years ago

shirleyquirk commented 3 years ago

Example

lib.nim

type
  Hidden = int
proc unexported() =
  var unused = newSeq[Hidden](0)

main.nim

import lib
var x = newSeq[int](1)
echo typeof(x)
let c = x[0]
echo typeof(c)

Current Output

please check whether the problem still exists in git head before posting, see rebuilding the compiler.

seq[Hidden]
Hidden

Expected Output

seq[int]
int

unearthed by https://forum.nim-lang.org/t/8561 caused user no end of confusion when an unexported (and undocumented) type in a dependency of a dependency was being printed in an error message.

behaviour exist in 1.6,1.4,1.2,1.0,0.20...

$ nim -v

Nim Compiler Version 1.7.1 [Linux: amd64] Compiled at 2021-10-30 Copyright (c) 2006-2021 by Andreas Rumpf

git hash: f755e452d2a2c7656f07793b7f01dc654a7c5253

Araq commented 3 years ago

More and more I'm off the opinion that we should "cache" generic instantiations only so far as required to prevent endless recursions in instantiations and then in a pre-linking step merge duplicated instantiations. This is what Borland C++ did with C++ templates and I don't remember complaints. It's conceptually simple and worked well.

metagn commented 3 weeks ago

Same is true vice versa, creating seq[int] first also makes seq[Hidden] be called seq[int].

An option is to skip all aliases in generic instantiations so it always gives seq[int].