Skip to content

import/using search order? #2375

Closed
Closed
@toivoh

Description

In the example below are three (top level) modules, ModA, Meta, and ModB. ModB attempts to use the other two.
The trouble is that ModB has an implicit using Base, which shadows the top level Meta module:

module ModA
export myvar_A
myvar_A=5
end

module Meta
export myvar_Meta
myvar_Meta=5
end

module ModB
using ModA, Meta
@show myvar_A
@show myvar_Meta
end

Running this in the repl gives me

myvar_A => 5
ERROR: myvar_Meta not defined

This behavior caused me the trouble in toivoh/Debug.jl#35: Debug.jl has a sub-module Debug.Meta. When Base.Meta was added, it shadowed Debug.Meta for the other Debug sub-modules. In general, it seems to me that the current behavior with implicit using Base risks to break existing code each time an export is added to Base.

My suggestion is to change name lookup within a module according to:

  • No implicit using Base in any module
  • If name lookup fails within a non-bare module, a lookup is made in Base as a fallback.

An alternative would be to change the interpretation of using to provide a fallback only if an identifier is not found in any other way.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

breakingThis change will break codeneeds decisionA decision on this change is needed

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions