diff --git a/src/dmd/dimport.d b/src/dmd/dimport.d index 4abd20b10819..fde24521e853 100644 --- a/src/dmd/dimport.d +++ b/src/dmd/dimport.d @@ -214,14 +214,7 @@ extern (C++) final class Import : Dsymbol if (!mod) return; // Failed mod.importAll(null); - if (mod.md && mod.md.isdeprecated && !sc.isDeprecated) - { - Expression msg = mod.md.msg; - if (StringExp se = msg ? msg.toStringExp() : null) - mod.deprecation(loc, "is deprecated - %s", se.string); - else - mod.deprecation(loc, "is deprecated"); - } + mod.checkImportDeprecation(loc, sc); if (sc.explicitProtection) protection = sc.protection; if (!isstatic && !aliasId && !names.dim) diff --git a/src/dmd/dmodule.d b/src/dmd/dmodule.d index 7809dcb49bc7..35004cad6157 100644 --- a/src/dmd/dmodule.d +++ b/src/dmd/dmodule.d @@ -1176,6 +1176,26 @@ extern (C++) final class Module : Package return needmoduleinfo || global.params.cov; } + /******************************************* + * Print deprecation warning if we're deprecated, when + * this module is imported from scope sc. + * + * Params: + * sc = the scope into which we are imported + * loc = the location of the import statement + */ + void checkImportDeprecation(const ref Loc loc, Scope* sc) + { + if (md && md.isdeprecated && !sc.isDeprecated) + { + Expression msg = md.msg; + if (StringExp se = msg ? msg.toStringExp() : null) + deprecation(loc, "is deprecated - %s", se.string); + else + deprecation(loc, "is deprecated"); + } + } + override Dsymbol search(const ref Loc loc, Identifier ident, int flags = SearchLocalsOnly) { /* Since modules can be circularly referenced, diff --git a/src/dmd/dsymbolsem.d b/src/dmd/dsymbolsem.d index edb3e6655440..69a4b0d43ded 100644 --- a/src/dmd/dsymbolsem.d +++ b/src/dmd/dsymbolsem.d @@ -1574,7 +1574,10 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor { loadErrored = imp.load(sc); if (imp.mod) + { imp.mod.importAll(null); + imp.mod.checkImportDeprecation(imp.loc, sc); + } } if (imp.mod) { diff --git a/test/fail_compilation/fail20163.d b/test/fail_compilation/fail20163.d new file mode 100644 index 000000000000..84822cfbe9d0 --- /dev/null +++ b/test/fail_compilation/fail20163.d @@ -0,0 +1,10 @@ +// REQUIRED_ARGS: -de +/* +TEST_OUTPUT: +--- +fail_compilation/fail20163.d-mixin-10(10): Deprecation: module `imports.fail20164` is deprecated +--- +*/ +module fail20163; + +mixin("import imports.fail20164;"); diff --git a/test/fail_compilation/fail20164.d b/test/fail_compilation/fail20164.d new file mode 100644 index 000000000000..540f77dcf097 --- /dev/null +++ b/test/fail_compilation/fail20164.d @@ -0,0 +1,13 @@ +// REQUIRED_ARGS: -de +/* +TEST_OUTPUT: +--- +fail_compilation/fail20164.d(12): Deprecation: module `imports.fail20164` is deprecated +--- +*/ +module fail20164; + +void foo() +{ + import imports.fail20164; +} diff --git a/test/fail_compilation/imports/fail20164.d b/test/fail_compilation/imports/fail20164.d new file mode 100644 index 000000000000..15d6359329fc --- /dev/null +++ b/test/fail_compilation/imports/fail20164.d @@ -0,0 +1 @@ +deprecated module imports.fail20164;