From 305f34e3ba8a46ba81e55c968c1da0f06fe3fe9e Mon Sep 17 00:00:00 2001 From: JinShil Date: Thu, 26 Jul 2018 16:16:00 +0900 Subject: [PATCH 1/2] Fix Issue 19107 - -de produces compilation error, -dw does not --- src/dmd/mtype.d | 11 +++++++++++ test/compilable/imports/test19107a.d | 3 +++ test/compilable/imports/test19107b.d | 3 +++ test/compilable/test19107.d | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 test/compilable/imports/test19107a.d create mode 100644 test/compilable/imports/test19107b.d create mode 100644 test/compilable/test19107.d diff --git a/src/dmd/mtype.d b/src/dmd/mtype.d index daeed79cd20d..0c03fabd425b 100644 --- a/src/dmd/mtype.d +++ b/src/dmd/mtype.d @@ -909,12 +909,23 @@ extern (C++) abstract class Type : RootObject final Type trySemantic(const ref Loc loc, Scope* sc) { //printf("+trySemantic(%s) %d\n", toChars(), global.errors); + + // Needed to display any deprecations that were gagged + auto tcopy = this.syntaxCopy(); + uint errors = global.startGagging(); Type t = typeSemantic(this, loc, sc); if (global.endGagging(errors) || t.ty == Terror) // if any errors happened { t = null; } + else + { + // If `typeSemantic` succeeded, that's great, but there may have been deprecations + // that were gagged due the the `startGagging` above. Run again to display those + // deprecations. https://issues.dlang.org/show_bug.cgi?id=19107 + typeSemantic(tcopy, loc, sc); + } //printf("-trySemantic(%s) %d\n", toChars(), global.errors); return t; } diff --git a/test/compilable/imports/test19107a.d b/test/compilable/imports/test19107a.d new file mode 100644 index 000000000000..d270e3b497bb --- /dev/null +++ b/test/compilable/imports/test19107a.d @@ -0,0 +1,3 @@ +module imports.test19107a.d; + +alias I(alias A) = A; diff --git a/test/compilable/imports/test19107b.d b/test/compilable/imports/test19107b.d new file mode 100644 index 000000000000..8fd8087ef932 --- /dev/null +++ b/test/compilable/imports/test19107b.d @@ -0,0 +1,3 @@ +module imports.test19107b; + +import imports.test19107a : I; diff --git a/test/compilable/test19107.d b/test/compilable/test19107.d new file mode 100644 index 000000000000..bfa64d285cb0 --- /dev/null +++ b/test/compilable/test19107.d @@ -0,0 +1,20 @@ +// REQUIRED_ARGS: -dw +/* +TEST_OUTPUT: +--- +compilable/test19107.d(14): Deprecation: `imports.test19107b.I` is not visible from module `test19107` +--- +*/ + +// https://issues.dlang.org/show_bug.cgi?id=19107 + +import imports.test19107b; + +void all(alias pred, T)(T t) + if (is(typeof(I!pred(t)))) +{ } + +void main(string[] args) +{ + args.all!(c => c); +} From c72fc35b4bd32bc84c62c0186de4a5e5565c54b3 Mon Sep 17 00:00:00 2001 From: JinShil Date: Thu, 26 Jul 2018 19:25:41 +0900 Subject: [PATCH 2/2] Only run typeSemantic twice if there are gagged warnings --- src/dmd/errors.d | 29 ++++++++++++++++++++++------- src/dmd/globals.d | 2 ++ src/dmd/mtype.d | 9 +++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/dmd/errors.d b/src/dmd/errors.d index 0c7c4fe9604d..9fcdb517381e 100644 --- a/src/dmd/errors.d +++ b/src/dmd/errors.d @@ -299,12 +299,18 @@ extern (C++) void verrorSupplemental(const ref Loc loc, const(char)* format, va_ */ extern (C++) void vwarning(const ref Loc loc, const(char)* format, va_list ap) { - if (global.params.warnings && !global.gag) + if (global.params.warnings) { - verrorPrint(loc, Classification.warning, "Warning: ", format, ap); - //halt(); - if (global.params.warnings == 1) - global.warnings++; // warnings don't count if gagged + if (!global.gag) + { + verrorPrint(loc, Classification.warning, "Warning: ", format, ap); + if (global.params.warnings == 1) + global.warnings++; + } + else + { + global.gaggedWarnings++; + } } } @@ -335,8 +341,17 @@ extern (C++) void vdeprecation(const ref Loc loc, const(char)* format, va_list a static __gshared const(char)* header = "Deprecation: "; if (global.params.useDeprecated == 0) verror(loc, format, ap, p1, p2, header); - else if (global.params.useDeprecated == 2 && !global.gag) - verrorPrint(loc, Classification.deprecation, header, format, ap, p1, p2); + else if (global.params.useDeprecated == 2) + { + if (!global.gag) + { + verrorPrint(loc, Classification.deprecation, header, format, ap, p1, p2); + } + else + { + global.gaggedWarnings++; + } + } } /** diff --git a/src/dmd/globals.d b/src/dmd/globals.d index 4d4a4481507c..312012bcff18 100644 --- a/src/dmd/globals.d +++ b/src/dmd/globals.d @@ -264,6 +264,7 @@ struct Global uint warnings; // number of warnings reported so far uint gag; // !=0 means gag reporting of errors & warnings uint gaggedErrors; // number of errors reported while gagged + uint gaggedWarnings; // number of warnings reported while gagged void* console; // opaque pointer to console for controlling text attributes @@ -275,6 +276,7 @@ struct Global extern (C++) uint startGagging() { ++gag; + gaggedWarnings = 0; return gaggedErrors; } diff --git a/src/dmd/mtype.d b/src/dmd/mtype.d index 0c03fabd425b..547310934359 100644 --- a/src/dmd/mtype.d +++ b/src/dmd/mtype.d @@ -921,10 +921,11 @@ extern (C++) abstract class Type : RootObject } else { - // If `typeSemantic` succeeded, that's great, but there may have been deprecations - // that were gagged due the the `startGagging` above. Run again to display those - // deprecations. https://issues.dlang.org/show_bug.cgi?id=19107 - typeSemantic(tcopy, loc, sc); + // If `typeSemantic` succeeded, there may have been deprecations that + // were gagged due the the `startGagging` above. Run again to display + // those deprecations. https://issues.dlang.org/show_bug.cgi?id=19107 + if (global.gaggedWarnings > 0) + typeSemantic(tcopy, loc, sc); } //printf("-trySemantic(%s) %d\n", toChars(), global.errors); return t;