June 26 [Issue 24632] New: Fully qualified package name in package requires import? | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24632 Issue ID: 24632 Summary: Fully qualified package name in package requires import? Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: zxinsworld@gmail.com When using the fully qualified name of a package inside that package you will receive either a deprecation message or an error, depending on how you referenced the fully qualified package name. To reproduce, first create a file called 'package.d'. This behaviour is ONLY present if the file name is 'package.d', so in other words this issue only applies to packages, not to regular modules. To get the deprecation message, paste this into package.d: ```d module bug.buggier; void main(){ alias thisModule = bug.buggier; } ``` To get an error, paste this into package.d: ```d module bug.buggier; void fn(){} void main(){ bug.buggier.fn(); } ``` Now compile. Expected result: it should work, just like how it works in any other module. Actual result: The compiler insists that you add `static import bug.buggier;`. Adding the static import makes everything compile* without any warnings, but why should you have to import a package into itself just for it to reference its own contents? If you don't use fully qualified names then the package's contents are freely available to itself. * Unless you use LDC2 & add the static import the 'to get an error' example, in which case LDC2 will crash hilariously. Tested with: - macOS 14.5 on aarch64 using LDC2 1.38.0 (based on DMD v2.108.1) - Debian on amd64 using DMD v2.106.1 -- |
Copyright © 1999-2021 by the D Language Foundation