Skip to content

Commit

Permalink
Fix issue 20163, fix issue 20164: print deprecation if a deprecated m…
Browse files Browse the repository at this point in the history
…odule is imported from a local function or a mixin.
  • Loading branch information
FeepingCreature committed Aug 25, 2019
1 parent bc2acbd commit 0c2dadb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/dmd/dimport.d
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions src/dmd/dmodule.d
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/dmd/dsymbolsem.d
Expand Up @@ -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)
{
Expand Down
10 changes: 10 additions & 0 deletions 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;");
13 changes: 13 additions & 0 deletions 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;
}
1 change: 1 addition & 0 deletions test/fail_compilation/imports/fail20164.d
@@ -0,0 +1 @@
deprecated module imports.fail20164;

0 comments on commit 0c2dadb

Please sign in to comment.