D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22329 - DMD and LDC2 Segumentation Faults due to alias this on private field + special names
Summary: DMD and LDC2 Segumentation Faults due to alias this on private field + specia...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-09-22 10:04 UTC by Marcelo Silva Nascimento Mancini
Modified: 2021-10-08 07: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 Marcelo Silva Nascimento Mancini 2021-09-22 10:04:05 UTC
That causes a sigsegfault on DMD without any error message
```d
public struct Foo {
    private int values;
    alias values this;
}

void main()
{
    writeln(Foo());
}
```

If the values variable is changed to "values2", then, a compiler error is being presented.

The mix of private and that special name causes an error, @jrfondren did a brute force test case for every word that happens: https://gist.github.com/jrfondren/78b5d366e37a6a9c4b91e37751f25789

@Mayonix helped me tracking that bug too by getting to the conclusion 
"So when you name a private field some function defined in object.d, alias this it, and then pass an object to a function in a different module which attempts to access the alias this, it can't access the field in question because it's private, so instead it finds the function defined in object.d,"
Comment 1 Dlang Bot 2021-10-03 08:26:26 UTC
@BorisCarvajal created dlang/dmd pull request #13119 "Fix Issue 22329 - DMD and LDC2 Segumentation Faults due to alias this" fixing this issue:

- Fix Issue 22329 - DMD and LDC2 Segumentation Faults due to alias this on private field + special names

https://github.com/dlang/dmd/pull/13119
Comment 2 Dlang Bot 2021-10-06 04:52:53 UTC
dlang/dmd pull request #13119 "Fix Issue 22329 - DMD and LDC2 Segumentation Faults due to alias this" was merged into stable:

- 1a1744d58212a7a8ff431b81ffa72239acb6da3a by Boris Carvajal:
  Fix Issue 22329 - DMD and LDC2 Segumentation Faults due to alias this on private field + special names

https://github.com/dlang/dmd/pull/13119
Comment 3 Dlang Bot 2021-10-08 07:02:45 UTC
dlang/dmd pull request #13140 "merge stable" was merged into master:

- 138559dbf6b472674170576b09193b96d6153ab8 by Boris Carvajal:
  Fix Issue 22329 - DMD and LDC2 Segumentation Faults due to alias this on private field + special names (#13119)

https://github.com/dlang/dmd/pull/13140