Way to be explicit with different objects sharing the same name?

Let’s say you have a module in a package called IO (obviously not preferable):

module IO
  custom_input_output_stuff = true
end

The problem now is that the module IO will clobber the Base IO type in calls.


This leads to the following errors:

> foo(bar::IO) = "nope, chuck testa"
ERROR: ArgumentError: invalid type for argument bar in method definition for foo at REPL[10]:100:

> struct Fizz ; buzz::IO ; end 
ERROR: TypeError: Fizz: in type definition, expected Type, got Module

How do you tell the package to use Base's IO when a type is expected?

edit: tangentially related to Julia Reserved/Key Words

Base.IO?

Sorry, but what about it?

The following doesn’t work:

> IO = Base.IO
ERROR: invalid redefinition of constant IO

// all the code above can be entered into the REPL

If I understand (which is a big “if”), your foo and Fizz only make since if the IO is Base.IO.

So I would make that

foo(bar::Base.IO) = "nope, chuck testa"

struct Fizz; buzz::Base.IO ; end
1 Like

That’s right. I was just wondering if there was a succinct way to do this without mass grep & replacing.

For this specific case, it seems like something looking for a Type object should find the Type form of IO and not error out?

No, currently there is no other way, but to use the fully-qualified name of a type.
e.g. Base.IO.

Namespacing issues like that are a problem, and one that deserves a better solution, but until there is one, either avoid reusing names like that or use fully qualified names.

1 Like