Skip to content

Commit 75b1c7c

Browse files
committed
Improve coverage + changelog
1 parent 90d089c commit 75b1c7c

4 files changed

Lines changed: 30 additions & 11 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
UDAs on function arguments are now supported
2+
3+
User-defined attributes on function arguments behave analogous to existing UDAs:
4+
5+
---
6+
void test(A)(@(22) A a)
7+
{
8+
static assert([__traits(getAttributes, a)] == [22]);
9+
}
10+
---

src/dmd/parse.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,7 +2778,7 @@ final class Parser(AST) : Lexer
27782778
StorageClass stc2 = parseAttribute(&exps);
27792779
if (stc2 == AST.STC.property || stc2 == AST.STC.nogc || stc2 == AST.STC.disable || stc2 == AST.STC.safe || stc2 == AST.STC.trusted || stc2 == AST.STC.system)
27802780
{
2781-
error("@%s attribute for function parameter is not supported", token.toChars());
2781+
error("`@%s` attribute for function parameter is not supported", token.toChars());
27822782
}
27832783
else
27842784
{
@@ -2865,6 +2865,7 @@ final class Parser(AST) : Lexer
28652865
}
28662866
default:
28672867
{
2868+
int i = 1;
28682869
stc = storageClass & (AST.STC.in_ | AST.STC.out_ | AST.STC.ref_ | AST.STC.lazy_);
28692870
// if stc is not a power of 2
28702871
if (stc & (stc - 1) && !(stc == (AST.STC.in_ | AST.STC.ref_)))
@@ -2920,7 +2921,7 @@ final class Parser(AST) : Lexer
29202921
StorageClass stc2 = parseAttribute(&exps);
29212922
if (stc2 == AST.STC.property || stc2 == AST.STC.nogc || stc2 == AST.STC.disable || stc2 == AST.STC.safe || stc2 == AST.STC.trusted || stc2 == AST.STC.system)
29222923
{
2923-
error("@%s attribute for function parameter is not supported", token.toChars());
2924+
error("`@%s` attribute for function parameter is not supported", token.toChars());
29242925
}
29252926
else
29262927
{

src/dmd/traits.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
719719
{
720720
if (!po.ident)
721721
{
722-
e.error("argument %s has no identifier", po.type.toChars());
722+
e.error("argument `%s` has no identifier", po.type.toChars());
723723
return new ErrorExp();
724724
}
725725
id = po.ident;

test/fail_compilation/udaparams.d

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/*
22
TEST_OUTPUT:
33
---
4-
fail_compilation/udaparams.d(15): Error: variadic parameter cannot have user-defined attributes
5-
fail_compilation/udaparams.d(16): Error: variadic parameter cannot have user-defined attributes
6-
fail_compilation/udaparams.d(18): Error: user-defined attributes cannot appear as postfixes
7-
fail_compilation/udaparams.d(19): Error: user-defined attributes cannot appear as postfixes
8-
fail_compilation/udaparams.d(20): Error: user-defined attributes cannot appear as postfixes
9-
fail_compilation/udaparams.d(22): Error: @safe attribute for function parameter is not supported
10-
fail_compilation/udaparams.d(23): Error: @safe attribute for function parameter is not supported
11-
fail_compilation/udaparams.d(24): Error: @safe attribute for function parameter is not supported
4+
fail_compilation/udaparams.d(18): Error: variadic parameter cannot have user-defined attributes
5+
fail_compilation/udaparams.d(19): Error: variadic parameter cannot have user-defined attributes
6+
fail_compilation/udaparams.d(21): Error: user-defined attributes cannot appear as postfixes
7+
fail_compilation/udaparams.d(22): Error: user-defined attributes cannot appear as postfixes
8+
fail_compilation/udaparams.d(23): Error: user-defined attributes cannot appear as postfixes
9+
fail_compilation/udaparams.d(25): Error: `@safe` attribute for function parameter is not supported
10+
fail_compilation/udaparams.d(26): Error: `@safe` attribute for function parameter is not supported
11+
fail_compilation/udaparams.d(27): Error: `@safe` attribute for function parameter is not supported
12+
fail_compilation/udaparams.d(30): Error: `@system` attribute for function parameter is not supported
13+
fail_compilation/udaparams.d(31): Error: `@trusted` attribute for function parameter is not supported
14+
fail_compilation/udaparams.d(32): Error: `@nogc` attribute for function parameter is not supported
1215
---
1316
*/
1417

@@ -22,3 +25,8 @@ void rhsuda3(int[] arr @(10) ...);
2225
void wrongAttr1(@safe int);
2326
void wrongAttr2(@safe void function());
2427
void wrongAttr3(@safe void delegate());
28+
29+
30+
void test16(A)(A a @system);
31+
void test16(A)(A a @trusted);
32+
void test16(A)(A a @nogc);

0 commit comments

Comments
 (0)