When type T is defined private in file test.nim and a public proc p (returns T) is defined in this file too, and test is imported in test2.nim, test.p can be used there but test.T can't and at the same time test.p returns T. I saw that this is forbidden in rust (https://github.com/rust-lang/rust/issues/22261) and I think it makes sense to forbid it. IIRC Go allows it, like Nim.
Was this discussed before for Nim?
There's nothing wrong in this in my opinion. It just means that T is an opaque type. You can get it from exported functions, and pass it to other exported functions, but you can't create one yourself or manipulate one without using one of the functions in the module that exports it. I would even say that this is a useful pattern.
For instance the following works:
#dep.nim
type T = object
x: int
proc makeT*(x: int): T = T(x: x)
proc printT*(t: T) =
echo t.x
and then
import dep
let t = makeT(12)
printT(t)
but the following does not compile
import dep
let t = T(x:12)