[Issue 23300] std.array : array wrongly propagates scopeness of source
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 24 15:22:42 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23300
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dkorpel at live.nl
--- Comment #2 from Dennis <dkorpel at live.nl> ---
(In reply to RazvanN from comment #1)
> However, `array`'s
> parameter cannot be `scope` because it is copied into allocated memory.
The parameter to `array` should infer `scope` unless the range has non-scope
range primitives. It's not escaping the input array, it's dereferencing it and
copying the elements into a new GC array which is not scope.
`scope` inference fails and it falls back on `return scope` inference from
`pure`. By making it impure, the newest DMD reports:
test_.d(12): Error: scope variable `r` assigned to non-scope parameter `r`
calling `array`
std/array.d(112): which is not `scope` because of `__r353 = r`
https://github.com/dlang/phobos/blob/b578dfad94770574d7e522557a77276c35943daa/std/array.d#L112
So the underlying problem is that `scope` inference is defeated by `foreach` on
a struct with range primitives.
--
More information about the Digitalmars-d-bugs
mailing list