Closed snocl closed 6 years ago
Hm. On one hand it's definitely weird, on the other hand, at the very least it makes sense to shadow the package name from within the package, so you can do:
var re : regex.regex
I think I'll make it work.
Turned out to be really easy.
My concrete case was similar: var board : board.board
. :)
Realized pretty quickly that shadowing it would mean I couldn’t access the related functions, though...
Yeah. It makes sense to do it from within a namespace, so you might have regex.regex(args)
. That used to be subject to the same aliasing weirdness, but I don't think I've ever exported a global struct, so I never ran into it.
From outside of a namespace, it's definitely less useful, but that's no excuse for stupid behavior.
If a variable is named the same as an imported package, its fields can’t be accessed normally. It can, however, be accessed indirectly through dereferencing. For example:
(If the field is a pointer then
std#.field
will work whilestd.field
will still fail.)I’d expect the correct behavior to either be a compile-time error when declaring the variable, or for the compiler to always have the local variable shadow the package.