-
-
Notifications
You must be signed in to change notification settings - Fork 676
Fix Issue 21651 - Unimported package doesn't error out when used as p… #12215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| Deprecate a case of using fully-qualified names to bypass imports | ||
|
|
||
| Since v2.084 it is no longer possible to bypass private imports by using fully-qualified names, | ||
| this was deprecated in v2.071 but when fully-qualified names are used as a type | ||
| (vs an expression) the code is accepted without any warning. | ||
|
|
||
| Starting with this release the compiler will now properly deprecate the previous omitted case. | ||
|
|
||
| The issue is best described in the following example: | ||
|
|
||
| ```d | ||
| import std.algorithm; | ||
|
|
||
| // deprecated in v2.071, error since v2.084 | ||
| auto a = std.range.Take!(int[]); // Error: undefined identifier `range` in package `std`... | ||
|
|
||
| // now it's deprecated, will be error from v2.106 | ||
| std.range.Take!(int[]) s; | ||
|
|
||
| ```` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ import dmd.declaration; | |
| import dmd.denum; | ||
| import dmd.dimport; | ||
| import dmd.dmangle; | ||
| import dmd.dmodule : Module; | ||
| import dmd.dmodule; | ||
| import dmd.dscope; | ||
| import dmd.dstruct; | ||
| import dmd.dsymbol; | ||
|
|
@@ -255,10 +255,22 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb | |
| int flags = t is null ? SearchLocalsOnly : IgnorePrivateImports; | ||
|
|
||
| Dsymbol sm = s.searchX(loc, sc, id, flags); | ||
| if (sm && !(sc.flags & SCOPE.ignoresymbolvisibility) && !symbolIsVisible(sc, sm)) | ||
| if (sm) | ||
| { | ||
| .error(loc, "`%s` is not visible from module `%s`", sm.toPrettyChars(), sc._module.toChars()); | ||
| sm = null; | ||
| if (!(sc.flags & SCOPE.ignoresymbolvisibility) && !symbolIsVisible(sc, sm)) | ||
| { | ||
| .error(loc, "`%s` is not visible from module `%s`", sm.toPrettyChars(), sc._module.toChars()); | ||
| sm = null; | ||
| } | ||
| // Same check as in Expression.semanticY(DotIdExp) | ||
| else if (sm.isPackage() && checkAccess(sc, cast(Package)sm)) | ||
| { | ||
| // @@@DEPRECATED_2.096@@@ | ||
| // Should be an error in 2.106. Just remove the deprecation call | ||
| // and uncomment the null assignment | ||
| deprecation(loc, "%s %s is not accessible here, perhaps add 'static import %s;'", sm.kind(), sm.toPrettyChars(), sm.toPrettyChars()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, is the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the exact message of the original deprecation.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. |
||
| //sm = null; | ||
| } | ||
| } | ||
| if (global.errors != errorsave) | ||
| { | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // REQUIRED_ARGS: -de | ||
| // EXTRA_SOURCES: imports/ice10598a.d imports/ice10598b.d | ||
| /* TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/imports/ice10598a.d(5): Deprecation: module imports.ice10598b is not accessible here, perhaps add 'static import imports.ice10598b;' | ||
| fail_compilation/imports/ice10598a.d(5): Deprecation: module imports.ice10598b is not accessible here, perhaps add 'static import imports.ice10598b;' | ||
| --- | ||
| */ | ||
|
|
||
| void main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module imports.test21651b; | ||
|
|
||
| alias T = int; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // REQUIRED_ARGS: -de | ||
| // EXTRA_SOURCES: imports/test21651b.d | ||
| /* TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/test21651.d(11): Deprecation: module imports.test21651b is not accessible here, perhaps add 'static import imports.test21651b;' | ||
| --- | ||
| */ | ||
|
|
||
| module imports.test21651; | ||
|
|
||
| imports.test21651b.T a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a result of fixing the bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's to fix a instance of the bug in DMD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two lines a little below:
dmd.glueis not imported but is working because of the bug.