Skip to content

Commit

Permalink
Merge pull request #1642 from AndrejMitrovic/Fix9484
Browse files Browse the repository at this point in the history
Issue 9484 - Selective and Renamed symbol imports should be separate.
  • Loading branch information
WalterBright authored and 9rnsr committed Feb 11, 2013
1 parent 7d955fe commit 4fd7a12
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 10 deletions.
38 changes: 30 additions & 8 deletions src/json.c
Expand Up @@ -739,19 +739,41 @@ void Import::toJson(JsonOut *json)
if (aliasId)
json->property("alias", aliasId->toChars());

if (names.dim)
bool hasRenamed = false;
bool hasSelective = false;
for (size_t i = 0; i < aliases.dim; i++)
{ // avoid empty "renamed" and "selective" sections
if (hasRenamed && hasSelective)
break;
else if (aliases[i])
hasRenamed = true;
else
hasSelective = true;
}

if (hasRenamed)
{
json->propertyStart("aliases");
json->arrayStart();
for (size_t i = 0; i < names.dim; i++)
// import foo : alias1 = target1;
json->propertyStart("renamed");
json->objectStart();
for (size_t i = 0; i < aliases.dim; i++)
{
Identifier *name = names[i];
Identifier *alias = aliases[i];
if (alias) json->property(alias->toChars(), name->toChars());
}
json->objectEnd();
}

if (alias)
json->property(alias->toChars(), name->toChars());
else
json->item(name->toChars());
if (hasSelective)
{
// import foo : target1;
json->propertyStart("selective");
json->arrayStart();
for (size_t i = 0; i < names.dim; i++)
{
Identifier *name = names[i];
if (!aliases[i]) json->item(name->toChars());
}
json->arrayEnd();
}
Expand Down
39 changes: 39 additions & 0 deletions test/compilable/extra-files/json.out
Expand Up @@ -304,6 +304,45 @@
"deco" : "FNbNdZi",
"originalType" : "nothrow int()",
"endline" : 74
},
{
"name" : "imports.jsonimport1",
"kind" : "import",
"line" : 77,
"protection" : "private",
"selective" : [
"target1",
"target2"
]
},
{
"name" : "imports.jsonimport2",
"kind" : "import",
"line" : 78,
"protection" : "private",
"renamed" : {
"alias1" : "target1",
"alias2" : "target2"
}
},
{
"name" : "imports.jsonimport3",
"kind" : "import",
"line" : 79,
"protection" : "private",
"renamed" : {
"alias3" : "target1",
"alias4" : "target2"
},
"selective" : [
"target3"
]
},
{
"name" : "imports.jsonimport4",
"kind" : "import",
"line" : 80,
"protection" : "private"
}
]
}
Expand Down
3 changes: 3 additions & 0 deletions test/compilable/imports/jsonimport1.d
@@ -0,0 +1,3 @@
module imports.jsonimport1;

int target1, target2;
3 changes: 3 additions & 0 deletions test/compilable/imports/jsonimport2.d
@@ -0,0 +1,3 @@
module imports.jsonimport2;

int target1, target2;
3 changes: 3 additions & 0 deletions test/compilable/imports/jsonimport3.d
@@ -0,0 +1,3 @@
module imports.jsonimport3;

int target1, target2, target3;
1 change: 1 addition & 0 deletions test/compilable/imports/jsonimport4.d
@@ -0,0 +1 @@
module imports.jsonimport4;
8 changes: 6 additions & 2 deletions test/compilable/json.d
Expand Up @@ -31,7 +31,7 @@ class Bar2 : Bar!1, Baz!(int, 2, null) {
class Bar3 : Bar2 {
private int val;
this(int i) { val = i; }

protected override Foo!int baz() { return Foo!int(val); }
}

Expand Down Expand Up @@ -73,4 +73,8 @@ body {
return x + z;
}


/** Issue 9484 - selective and renamed imports */
import imports.jsonimport1 : target1, target2;
import imports.jsonimport2 : alias1 = target1, alias2 = target2;
import imports.jsonimport3 : alias3 = target1, alias4 = target2, target3;
import imports.jsonimport4;

0 comments on commit 4fd7a12

Please sign in to comment.