Bug 19777 – [REG2.086a] SortedRange.opSlice is wrongly `@trusted`

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-03-30T11:53:25Z
Last change time
2019-04-28T14:14:29Z
Keywords
pull
Assigned to
No Owner
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2019-03-30T11:53:25Z
The following code used to be rejected correctly (up to 2.085). It compiles with git master (3b4ec9299). Introduced in <https://github.com/dlang/phobos/pull/6866>. ---- import std.range: SortedRange; struct R { int[] a; @safe { @property bool empty() { return a.length == 0; } @property ref int front() { return a[0]; } @property ref int back() { return a[$ - 1]; } void popFront() { a = a[1 .. $]; } void popBack() { a = a[0 .. $ - 1]; } @property R save() { return this; } ref int opIndex(size_t i) { return a[i]; } size_t length() { return a.length; } } R opSlice(size_t x, size_t y) @system { import core.stdc.stdio; printf("This is @system code.\n"); return R(a[x .. y]); } } void main() @safe { SortedRange!R s; auto sliced = s[0 .. 0]; /* Prints "This is @system code.". Should fail compilation. */ } ----
Comment #1 by dlang-bot — 2019-04-28T12:30:26Z
@MartinNowak created dlang/phobos pull request #6984 "fix Issue 19777 - SortedRange.opSlice should infer safety" fixing this issue: - fix Issue 19777 - SortedRange.opSlice should infer safety - unittests did fail with DIP1000 due to missing return scope inference in chained range, thus leading to a scope violation which prevented `@safe` inference - fixed unittests by adding return scope to chain.Result - would still fail under dip1000 with other ranges that miss return scope on their opSlice - should not have any effect on non-DIP1000 usage https://github.com/dlang/phobos/pull/6984
Comment #2 by dlang-bot — 2019-04-28T14:14:29Z
dlang/phobos pull request #6984 "fix Issue 19777 - SortedRange.opSlice should infer safety" was merged into stable: - 8430584344dc75c715d5db6442ad7aa336837659 by Martin Nowak: fix Issue 19777 - SortedRange.opSlice should infer safety - unittests did fail with DIP1000 due to missing return scope inference in chained range, thus leading to a scope violation which prevented `@safe` inference - fixed unittests by adding return scope to chain.Result - would still fail under dip1000 with other ranges that miss return scope on their opSlice - should not have any effect on non-DIP1000 usage https://github.com/dlang/phobos/pull/6984