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 20682 - [DIP1000] wrong error: scope variable may not be co… #10935

Merged
merged 2 commits into from Mar 19, 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
5 changes: 5 additions & 0 deletions src/dmd/escape.d
Expand Up @@ -1555,6 +1555,8 @@ void escapeByValue(Expression e, EscapeByResults* er, bool live = false)

override void visit(CastExp e)
{
if (!e.type.hasPointers())
return;
Type tb = e.type.toBasetype();
if (tb.ty == Tarray && e.e1.type.toBasetype().ty == Tsarray)
{
Expand Down Expand Up @@ -1651,6 +1653,9 @@ void escapeByValue(Expression e, EscapeByResults* er, bool live = false)
else
return;

if (!e.type.hasPointers())
return;

if (e.arguments && e.arguments.dim)
{
/* j=1 if _arguments[] is first argument,
Expand Down
20 changes: 20 additions & 0 deletions test/compilable/scope.d
Expand Up @@ -94,3 +94,23 @@ void test(scope ref D d) @safe
D[] da;
da ~= D(d.pos, null);
}

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

int f1_20682(return scope ref D d) @safe
{
return d.pos;
}

ref int f2_20682(return scope ref D d) @safe
{
return d.pos;
}

void test_20682(scope ref D d) @safe
{
int[] a;
a ~= f1_20682(d);
a ~= f2_20682(d);
a ~= cast(int) d.p;
}