dao
dao copied to clipboard
Multiple files with same namespace does not work as expected
ns1.dao:
namespace ns { DoSomething };
routine DoSomething()
{
io.writeln("Something");
}
ns2.dao:
namespace ns { DoSomethingElse };
routine DoSomethingElse()
{
io.writeln("Something Else");
}
Interactive console:
(dao) load ns1
= none
(dao) load ns2
= none
(dao) ns.DoSomething()
Something
= none
(dao) ns.DoSomethingElse()
[[ERROR]] in file "code string":
At line 1 : invalid constant expression;
At line 1 : Constant evaluation aborted with exception(s) ---
[[Error::Field]] --- Invalid field:
invalid field
In code snippet:
>> 0 : DATA : 0 , 0 , 0 ; 0;
Raised by: (), at instruction 0 in line 0 in file "interactive codes";
I would expect this to work like namespaces in C++ - if the same namespace name exists in multiple files they should get combined. However, if they're NOT going to be combined, I would expect this to be an error. It's currently a silent failure.
(I'm aware this can be resolved by giving the two a common file that defines the namespace and having them both import that, but that seems clunky and unnecessary. They should be able to simply silently combine namespaces of the same name. It works well in C++ so there is good precedent to make it work that way.)
However, if they're NOT going to be combined, I would expect this to be an error. It's currently a silent failure.
Agree, this should at least be brought to the user's attention. However, if the VM is able to detect that, it should also be able to merge namespaces properly.
This issue has been already discussed in https://github.com/daokoder/dao/issues/262 .
I have to say that I personally disagree with the resolution of #262, that if two different people write two different files that use the same namespace it should be able to merge them. BUT, even if that's not the case, the main issue here is that it just ignores one silently. It should at LEAST be flagged as an error.
I've written code to merge namespaces with the same name (surprisingly little code at that), but I'm going to hold onto it until my currently open pull request gets addressed.