Skip to content

Commit 8dbb5a0

Browse files
authored
so getFunctionAttributes() behaves like hdrgen.d (dlang#21405)
1 parent 68b5957 commit 8dbb5a0

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

compiler/src/dmd/mtype.d

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4294,12 +4294,32 @@ void attributesApply(const TypeFunction tf, void delegate(string) dg, TRUSTforma
42944294
dg("@nogc");
42954295
if (tf.isProperty)
42964296
dg("@property");
4297+
4298+
/* The following is more or less like dmd.hdrgen.stcToBuffer(), in the future
4299+
* it should be merged. The idea is consistent ordering
4300+
*/
4301+
STC stc;
42974302
if (tf.isRef)
4298-
dg("ref");
4303+
stc |= STC.ref_;
42994304
if (tf.isReturn && !tf.isReturnInferred)
4300-
dg("return");
4305+
stc |= STC.return_;
43014306
if (tf.isScopeQual && !tf.isScopeInferred)
4302-
dg("scope");
4307+
stc |= STC.scope_;
4308+
if (tf.isReturnScope)
4309+
stc |= STC.returnScope;
4310+
final switch (buildScopeRef(stc))
4311+
{
4312+
case ScopeRef.None: break;
4313+
case ScopeRef.Scope: dg("scope"); break;
4314+
case ScopeRef.Return: dg("return"); break;
4315+
case ScopeRef.ReturnScope: dg("return"); dg("scope"); break;
4316+
case ScopeRef.ReturnRef: dg("return"); dg("ref"); break;
4317+
case ScopeRef.Ref: dg("ref"); break;
4318+
case ScopeRef.RefScope: dg("ref"); dg("scope"); break;
4319+
case ScopeRef.ReturnRef_Scope: dg("return"); dg("ref"); dg("scope"); break;
4320+
case ScopeRef.Ref_ReturnScope: dg("ref"); dg("return"); dg("scope"); break;
4321+
}
4322+
43034323
if (tf.isLive)
43044324
dg("@live");
43054325

compiler/test/compilable/traits_getFunctionAttributes.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ void test_getFunctionAttributes()
4444
static assert(__traits(getFunctionAttributes, S.sharedF) == tuple!("shared", "@system"));
4545
static assert(__traits(getFunctionAttributes, typeof(S.sharedF)) == tuple!("shared", "@system"));
4646

47-
static assert(__traits(getFunctionAttributes, S.refF) == tuple!("ref", "return", "@system"));
48-
static assert(__traits(getFunctionAttributes, typeof(S.refF)) == tuple!("ref", "return", "@system"));
47+
static assert(__traits(getFunctionAttributes, S.refF) == tuple!("return", "ref", "@system"));
48+
static assert(__traits(getFunctionAttributes, typeof(S.refF)) == tuple!("return", "ref", "@system"));
4949

5050
static assert(__traits(getFunctionAttributes, S.propertyF) == tuple!("@property", "@system"));
5151
static assert(__traits(getFunctionAttributes, typeof(&S.propertyF)) == tuple!("@property", "@system"));

compiler/test/fail_compilation/test21546.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
fail_compilation/test21546.d(113): Error: cannot implicitly convert expression `pc` of type `const(int)* delegate() return` to `int* delegate() return`
44
fail_compilation/test21546.d(114): Error: cannot implicitly convert expression `pc` of type `const(int)* delegate() return` to `immutable(int)* delegate() return`
55
fail_compilation/test21546.d(115): Error: cannot implicitly convert expression `pi` of type `immutable(int)* delegate() return` to `int* delegate() return`
6-
fail_compilation/test21546.d(213): Error: cannot implicitly convert expression `dc` of type `const(int) delegate() ref return` to `int delegate() ref return`
7-
fail_compilation/test21546.d(214): Error: cannot implicitly convert expression `dc` of type `const(int) delegate() ref return` to `immutable(int) delegate() ref return`
8-
fail_compilation/test21546.d(215): Error: cannot implicitly convert expression `di` of type `immutable(int) delegate() ref return` to `int delegate() ref return`
9-
fail_compilation/test21546.d(305): Error: cannot implicitly convert expression `[dgi]` of type `immutable(int) delegate() ref return[]` to `int delegate() ref return[]`
6+
fail_compilation/test21546.d(213): Error: cannot implicitly convert expression `dc` of type `const(int) delegate() return ref` to `int delegate() return ref`
7+
fail_compilation/test21546.d(214): Error: cannot implicitly convert expression `dc` of type `const(int) delegate() return ref` to `immutable(int) delegate() return ref`
8+
fail_compilation/test21546.d(215): Error: cannot implicitly convert expression `di` of type `immutable(int) delegate() return ref` to `int delegate() return ref`
9+
fail_compilation/test21546.d(305): Error: cannot implicitly convert expression `[dgi]` of type `immutable(int) delegate() return ref[]` to `int delegate() return ref[]`
1010
---
1111
*/
1212
// https://issues.dlang.org/show_bug.cgi?id=21546

compiler/test/runnable/testscope2.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
TEST_OUTPUT:
44
---
5-
foo1 ulong function(return ref int* delegate() return p) ref return
5+
foo1 ulong function(return ref int* delegate() return p) return ref
66
foo2 int function(return ref int delegate() p) ref
77
foo3 int function(ref inout(int*) p) ref
88
foo4 int function(return ref inout(int*) p) ref

0 commit comments

Comments
 (0)