Bug 22117 – Can't store scope pointer in a SumType

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-12T00:29:11Z
Last change time
2021-08-24T13:16:17Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus
Depends on
22118, 22226

Comments

Comment #0 by snarwin+bugzilla — 2021-07-12T00:29:11Z
As of DMD 2.097.0, the following program fails to compile with `-preview=dip1000`: --- void main() @safe { import std.sumtype; int n = 123; SumType!(int*) s = &n; } --- The error message is: --- Error: reference to local variable `n` assigned to non-scope parameter `value` calling std.sumtype.SumType!(int*).SumType.this --- Since the sumtype instance `s` is a local variable with shorter lifetime than `n`, it should be able to store a pointer to `n`.
Comment #1 by dlang-bot — 2021-08-23T14:07:53Z
@pbackus created dlang/phobos pull request #8208 "Fix Issue 22117 - Can't store scope pointer in a SumType" fixing this issue: - Fix Issue 22117 - Can't store scope pointer in a SumType Previously, the assignment of the local variable 'newStorage' to the longer-lived member variable 'storage' caused scope inference to (correctly) fail. newStorage was necessary to work around issues 21229 and 22118. Since those issues have been fixed, newStorage can be safely removed. https://github.com/dlang/phobos/pull/8208
Comment #2 by dlang-bot — 2021-08-24T13:16:17Z
dlang/phobos pull request #8208 "Fix Issue 22117 - Can't store scope pointer in a SumType" was merged into master: - 5ac515b52c7bb19d81303e4d89e80a6faeaf9028 by Paul Backus: Fix Issue 22117 - Can't store scope pointer in a SumType Previously, the assignment of the local variable 'newStorage' to the longer-lived member variable 'storage' caused scope inference to (correctly) fail. newStorage was necessary to work around issues 21229 and 22118. Since those issues have been fixed, newStorage can be safely removed. https://github.com/dlang/phobos/pull/8208