Type name clashes

I just noticed this:

Works:

module Foo
struct Array end
end

Fails with ERROR: cannot assign variable Core.Array from module Foo:

module Foo
dump(Array)
struct Array end
end

Is the conclusion that adding a type that is named the same as a type in Base is disallowed now? I’m asking because some code in CxxWrap that creates (non-exported) types named e.g. Array seems to fail now in 1.0, and I’m wondering if this is because of a new rule or because I am creating the type using the C interface. I also wonder why it only fails in the second case.

No. But you can’t change the meaning of a const symbol after using it.

Aha, that’s indeed what causes this. It seems that checking if a symbol is defined already means it is used, currently I use this code:

jl_datatype_t* existing_datatype(jl_module_t* mod, jl_sym_t* name)
{
  jl_datatype_t* found_dt = (jl_datatype_t*)jl_get_global(mod, name);
  if(found_dt != nullptr && found_dt->name->module == mod)
  {
    return found_dt;
  }
  return nullptr;
}

Is there a way to check if a type is defined in a module without having the symbol marked as used? I am doing this check because of precompilation, to see if the type is available from precompilation or if it needs to be created.