Fix bugzilla 24583 - di generator emits return scope and scope return in wrong order (#16595)

This commit is contained in:
Dennis 2024-06-18 16:12:59 +02:00 committed by GitHub
parent 3457a5902d
commit c0fcaa0e96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 28 additions and 10 deletions

View file

@ -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")
@ -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)
{
@ -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");
}

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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()`?
---
*/