Bug 20937 – std.range.array of a lengthless range with indirection is not @safe

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-16T10:47:51Z
Last change time
2021-08-31T06:13:39Z
Keywords
pull, safe
Assigned to
Ate Eskola
Creator
Mathias LANG

Comments

Comment #0 by pro.mathias.lang — 2020-06-16T10:47:51Z
``` import std.algorithm; import std.array; struct S { ulong[] values; } void main () @safe { immutable arr = [ S([1]), S([2]), S([3]), S([4]), S([42]), S([84]), S([121]) ]; auto intermediate = arr.filter!(v => !!(v.values[0] % 2)); auto result = intermediate.array; } ``` What I expected: `result` should be of a type that converts to `immutable(S)[]`. What I got: ``` foo.d(13): Error: @safe function D main cannot call @system function std.array.array!(FilterResult!(__lambda1, immutable(S)[])).array /usr/local/opt/dmd/include/dlang/dmd/std/array.d(102): std.array.array!(FilterResult!(__lambda1, immutable(S)[])).array is declared here ```
Comment #1 by Ajieskola — 2021-08-16T19:15:51Z
Reduced test case: ``` struct S {int* x;} void main() @safe { import std.algorithm, std.array; auto result = (new immutable(S)[2]).filter!(v => true).array; } ```
Comment #2 by Ajieskola — 2021-08-17T21:29:38Z
I have fixed this, but not pushed yet because I have procrastinated with moving out of password-based authentication that GitHub does not accept anymore. Will push once my authentication from terminal works again.
Comment #3 by dlang-bot — 2021-08-19T22:57:41Z
@dukc created dlang/phobos pull request #8202 "fix issue 20937" fixing this issue: - fix issue 20937 - std.range.array of a lengthless range with indirection is not @safe https://github.com/dlang/phobos/pull/8202
Comment #4 by dlang-bot — 2021-08-31T06:13:39Z
dlang/phobos pull request #8202 "fix issue 20937 - std.range.array of a lengthless range with indirection is not @safe" was merged into stable: - c5c559343dc458936aa29f3fa75e23ab86ac717e by Ate Eskola: fix issue 20937 - std.range.array of a lengthless range with indirection is not @safe https://github.com/dlang/phobos/pull/8202