Skip to content

Commit

Permalink
Fix bugzilla 24583 - di generator emits return scope and scope return…
Browse files Browse the repository at this point in the history
… in wrong order (#16595)
  • Loading branch information
dkorpel authored Jun 18, 2024
1 parent 3457a59 commit c0fcaa0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
16 changes: 12 additions & 4 deletions compiler/src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -3933,9 +3933,9 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te
buf.writeByte(' ');
}

void ignoreReturn(string str)
void dg(string str)
{
if (str != "return")
if (str != "return" && str != "scope")
{
// don't write 'ref' for ctors
if ((ident == Id.ctor) && str == "ref")
Expand All @@ -3944,7 +3944,7 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te
buf.writeByte(' ');
}
}
t.attributesApply(&ignoreReturn);
t.attributesApply(&dg);

if (t.linkage > LINK.d && hgs.ddoc != 1 && !hgs.hdrgen)
{
Expand Down Expand Up @@ -3977,7 +3977,15 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te
buf.writeByte(')');
}
parametersToBuffer(t.parameterList, buf, hgs);
if (t.isreturn)
if (t.isreturnscope && !t.isreturninferred)
{
buf.writestring(" return scope");
}
else if (t.isScopeQual && !t.isscopeinferred)
{
buf.writestring(" scope");
}
if (t.isreturn && !t.isreturnscope && !t.isreturninferred)
{
buf.writestring(" return");
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/test/compilable/extra-files/header1.d
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,17 @@ struct SafeS
return this;
}

ref SafeS foo3() return scope
ref SafeS foo3() scope
{
static SafeS s;
return s;
}

ref SafeS foo4() scope return
{
return this;
}

int* p;
}

Expand Down
5 changes: 3 additions & 2 deletions compiler/test/compilable/extra-files/header1.di
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,9 @@ struct SafeS
@safe
{
ref SafeS foo() return;
scope SafeS foo2() return;
ref scope SafeS foo3() return;
SafeS foo2() return scope;
ref SafeS foo3() scope;
ref SafeS foo4() scope return;
int* p;
}
}
Expand Down
8 changes: 6 additions & 2 deletions compiler/test/compilable/extra-files/header1i.di
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,19 @@ struct SafeS
{
return this;
}
scope SafeS foo2() return
SafeS foo2() return scope
{
return this;
}
ref scope SafeS foo3() return
ref SafeS foo3() scope
{
static SafeS s;
return s;
}
ref SafeS foo4() scope return
{
return this;
}
int* p;
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/retref2.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TEST_OUTPUT:
---
fail_compilation/retref2.d(18): Error: function `ref int retref2.D.foo(return ref int)` does not override any function, did you mean to override `ref int retref2.C.foo(ref int)`?
fail_compilation/retref2.d(19): Error: function `ref scope int retref2.D.bar() return` does not override any function, did you mean to override `ref int retref2.C.bar()`?
fail_compilation/retref2.d(19): Error: function `ref int retref2.D.bar() scope return` does not override any function, did you mean to override `ref int retref2.C.bar()`?
---
*/

Expand Down

0 comments on commit c0fcaa0

Please sign in to comment.