Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes Issue 8922 - __traits(parent) should fail on top package import

  • Loading branch information...
commit 8b31b3d8171abd9e06e1b7f18201fbe25fde20e3 1 parent 8587727
Andrej Mitrović AndrejMitrovic authored
5 src/traits.c
View
@@ -267,9 +267,10 @@ Expression *TraitsExp::semantic(Scope *sc)
{
if (FuncDeclaration *fd = s->isFuncDeclaration()) // Bugzilla 8943
s = fd->toAliasFunc();
- s = s->toParent();
+ if (!s->isImport()) // Bugzilla 8922
+ s = s->toParent();
}
- if (!s)
+ if (!s || s->isImport())
{
error("argument %s has no parent", o->toChars());
goto Lfalse;
1  test/compilable/imports/bug8922.d
View
@@ -0,0 +1 @@
+module imports.bug8922;
9 test/compilable/test8922a.d
View
@@ -0,0 +1,9 @@
+// PERMUTE_ARGS:
+import imports.bug8922;
+
+void test()
+{
+ static assert(!__traits(compiles, __traits(parent, imports)));
+ enum x = __traits(parent, imports.bug8922).stringof;
+ static assert(x == "package imports");
+}
9 test/compilable/test8922b.d
View
@@ -0,0 +1,9 @@
+// PERMUTE_ARGS:
+void test()
+{
+ import imports.bug8922;
+ static assert(!__traits(compiles, __traits(parent, imports)));
+ enum x = __traits(parent, imports.bug8922).stringof;
+ static assert(x == "package imports");
+}
+
10 test/compilable/test8922c.d
View
@@ -0,0 +1,10 @@
+// PERMUTE_ARGS:
+static import imports.bug8922;
+
+void test()
+{
+ static assert(!__traits(compiles, __traits(parent, imports)));
+ static assert(!__traits(compiles, __traits(parent, bug8922)));
+ enum x = __traits(parent, imports.bug8922).stringof;
+ static assert(x == "package imports");
+}
10 test/compilable/test8922d.d
View
@@ -0,0 +1,10 @@
+// PERMUTE_ARGS:
+void test()
+{
+ static import imports.bug8922;
+ static assert(!__traits(compiles, __traits(parent, imports)));
+ static assert(!__traits(compiles, __traits(parent, bug8922)));
+ enum x = __traits(parent, imports.bug8922).stringof;
+ static assert(x == "package imports");
+}
+
11 test/compilable/test8922e.d
View
@@ -0,0 +1,11 @@
+// PERMUTE_ARGS:
+import renamed = imports.bug8922;
+
+void test()
+{
+ enum x = __traits(parent, renamed).stringof;
+ static assert(x == "package imports");
+ static assert(!__traits(compiles, __traits(parent, imports)));
+ static assert(!__traits(compiles, __traits(parent, bug8922)));
+ static assert(!__traits(compiles, __traits(parent, imports.bug8922)));
+}
10 test/compilable/test8922f.d
View
@@ -0,0 +1,10 @@
+// PERMUTE_ARGS:
+void test()
+{
+ import renamed = imports.bug8922;
+ enum x = __traits(parent, renamed).stringof;
+ static assert(x == "package imports");
+ static assert(!__traits(compiles, __traits(parent, imports)));
+ static assert(!__traits(compiles, __traits(parent, bug8922)));
+ static assert(!__traits(compiles, __traits(parent, imports.bug8922)));
+}
Please sign in to comment.
Something went wrong with that request. Please try again.