Skip to content
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

Fix Issue 20831 - __traits(getAttributes) failes to compile when used… #11284

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
ti = dsym._init ? dsym._init.syntaxCopy() : null;

StorageClass storage_class = STC.temp | dsym.storage_class;
if (arg.storageClass & STC.parameter)
if ((dsym.storage_class & STC.parameter) && (arg.storageClass & STC.parameter))
storage_class |= arg.storageClass;
auto v = new VarDeclaration(dsym.loc, arg.type, id, ti, storage_class);
//printf("declaring field %s of type %s\n", v.toChars(), v.type.toChars());
Expand Down
3 changes: 2 additions & 1 deletion src/dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol
continue;
// don't add it, if it has no name
auto v = new VarDeclaration(loc, fparam.type, fparam.ident, null);
fparam.storageClass |= STC.parameter;
v.storage_class = fparam.storageClass;
v.dsymbolSemantic(scx);
if (!ti.symtab)
Expand Down Expand Up @@ -6591,7 +6592,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol
tiargs.reserve(dim);
foreach (i, arg; *tt.arguments)
{
if (flags & 2 && (arg.ident || arg.userAttribDecl))
if (flags & 2 && (arg.storageClass & STC.parameter))
tiargs.insert(j + i, arg);
else
tiargs.insert(j + i, arg.type);
Expand Down
1 change: 0 additions & 1 deletion src/dmd/dtoh.d
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,6 @@ public:
}
ident = p.ident;
p.type.accept(this);
assert(!(p.storageClass & ~(AST.STC.ref_)));
if (p.storageClass & AST.STC.ref_)
buf.writeByte('&');
buf.writeByte(' ');
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -3011,7 +3011,7 @@ final class Parser(AST) : Lexer
if (hasdefault)
error("default argument expected for `%s`", ai ? ai.toChars() : at.toChars());
}
auto param = new AST.Parameter(storageClass, at, ai, ae, null);
auto param = new AST.Parameter(storageClass | STC.parameter, at, ai, ae, null);
if (udas)
{
auto a = new AST.Dsymbols();
Expand Down Expand Up @@ -4962,7 +4962,7 @@ final class Parser(AST) : Lexer
parameterList.parameters = new AST.Parameters();
Identifier id = Identifier.generateId("__T");
AST.Type t = new AST.TypeIdentifier(loc, id);
parameterList.parameters.push(new AST.Parameter(0, t, token.ident, null, null));
parameterList.parameters.push(new AST.Parameter(STC.parameter, t, token.ident, null, null));

tpl = new AST.TemplateParameters();
AST.TemplateParameter tp = new AST.TemplateTypeParameter(loc, id, null, null);
Expand Down
4 changes: 3 additions & 1 deletion src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,11 @@ extern(C++) Type typeSemantic(Type t, const ref Loc loc, Scope* sc)
for (size_t i = 0; i < dim; i++)
{
Parameter fparam = tf.parameterList[i];
fparam.storageClass |= STC.parameter;
mtype.inuse++;
fparam.type = fparam.type.typeSemantic(loc, argsc);
mtype.inuse--;

if (fparam.type.ty == Terror)
{
errors = true;
Expand Down Expand Up @@ -1473,7 +1475,7 @@ extern(C++) Type typeSemantic(Type t, const ref Loc loc, Scope* sc)
}
fparam.type = new TypeTuple(newparams);
}
fparam.storageClass = 0;
fparam.storageClass = STC.parameter;

/* Reset number of parameters, and back up one to do this fparam again,
* now that it is a tuple
Expand Down
8 changes: 8 additions & 0 deletions test/runnable/uda.d
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,14 @@ void test20()
});
}

/************************************************/
// https://issues.dlang.org/show_bug.cgi?id=20831

void foo20831(int f, float, @("test") string s = "test") {}

static if(is(typeof(foo20831) Params20831 == __parameters))
static assert([__traits(getAttributes, Params20831[1..2])] == []);

/************************************************/

int main()
Expand Down