D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20559 - Reference type + alias this + AA + AA.clear causes SEGV
Summary: Reference type + alias this + AA + AA.clear causes SEGV
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-02-03 18:24 UTC by Mathias LANG
Modified: 2020-02-04 00:02 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias LANG 2020-02-03 18:24:12 UTC
Test code:
```
import std.stdio;

class Bar
{
    int[string] aa;
    alias aa this;
}

void main ()
{
    scope b = new Bar;
    b["Hello"] = 42;
    b.clear; // SEGV happens here, next line is never reached
    writeln("Oopsie");
}
```

This happens because 'clear' is defined as:
> void clear(T : Value[Key], Value, Key)(T aa)

And the code just blindly casts T to a `struct AA`:
https://github.com/dlang/druntime/blob/1049bb806679436103f8174c1f77541d5ad99091/src/object.d#L2167-L2170
Comment 1 Dlang Bot 2020-02-03 18:38:09 UTC
@Geod24 created dlang/druntime pull request #2927 "Fix issue 20559: AA.clear segfault when used with alias this" fixing this issue:

- Fix issue 20559: AA.clear segfault when used with alias this

https://github.com/dlang/druntime/pull/2927
Comment 2 Dlang Bot 2020-02-04 00:02:39 UTC
dlang/druntime pull request #2927 "Fix issue 20559: AA.clear segfault when used with alias this" was merged into stable:

- 261124ff0aeb6ac577421045e7fa99f261796316 by Geod24:
  Fix issue 20559: AA.clear segfault when used with alias this

https://github.com/dlang/druntime/pull/2927