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 21324 - @live not detecting overwrite of Owner without disp… #11881

Merged
merged 1 commit into from Mar 25, 2022
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/ob.d
Expand Up @@ -1977,7 +1977,12 @@ void checkObErrors(ref ObState obstate)
else if (isReadonlyPtr(v))
pvs.state = PtrState.Readonly;
else
{
if (pvs.state == PtrState.Owner && v.type.hasPointersToMutableFields())
v.error(e.loc, "assigning to Owner without disposing of owned value");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message could be improved, how about

is assigned to Owner %s (which?) without disposing of owned value %s (what?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a supplemental error, hinting at how we can workaround this error might be helpful.


pvs.state = PtrState.Owner;
}
pvs.deps.zero();

EscapeByResults er;
Expand Down
1 change: 1 addition & 0 deletions test/fail_compilation/fob1.d
Expand Up @@ -17,6 +17,7 @@ fail_compilation/fob1.d(104): Error: variable `fob1.foo1.p` is returned but is U

/* TEST_OUTPUT:
---
fail_compilation/fob1.d(204): Error: variable `fob1.foo2.p` assigning to Owner without disposing of owned value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that a null pointer has to be disposed. Is this really what we want?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also weird that a null pointer can be left dangling, but currently null is seen equally as any other pointer.

fail_compilation/fob1.d(203): Error: variable `fob1.foo2.p` is left dangling at return
---
*/
Expand Down
18 changes: 18 additions & 0 deletions test/fail_compilation/fob2.d
Expand Up @@ -175,3 +175,21 @@ void free7(int*);
{
free7(p);
}

/* TEST_OUTPUT:
---
fail_compilation/fob2.d(807): Error: variable `fob2.test8.p` assigning to Owner without disposing of owned value
---
*/

#line 800

int* malloc8();
void free8(int*);

@live void test8()
{
int* p = malloc8();
p = malloc8(); // error here
free8(p);
}