microsoft / qsharp-compiler

Q# compiler, command line tool, and Q# language server
https://docs.microsoft.com/quantum
MIT License
682 stars 171 forks source link

Q# callables should not have same fully qualified name as another namespace #575

Closed swernli closed 4 years ago

swernli commented 4 years ago

This issue is copied from https://github.com/microsoft/qsharp-runtime/issues/245. When a Q# callable has a fully qualified name that exactly matches the name of another namespace, it becomes very hard to disambiguate them. This specifically causes problems in C# generation, but is really more a generally bad thing to do. We should detect and flag this in the compiler so that developers know early that the given name will not work.

For example, this code is currently accepted by the compiler:

namespace Foo {
    function Bar() : Unit { }
}

namespace Foo.Bar {
    function Hello() : Unit { }
}

But the function Bar has the fully qualified name Foo.Bar which collides with the namespace of the same name. This should not be allowed.

cgranade commented 4 years ago
namespace Baz {
    function Bar() : Unit { }
}

namespace Foo.Bar {
    open Baz as Foo; // is this bad as well?
    function Hello() : Unit { }
}
bettinaheim commented 4 years ago

@cgranade No, that is fine, since everything is resolved to fully qualified names upon compilation the issue only arises if the clash is with the full name.

bettinaheim commented 4 years ago

Fixed with #647.