D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20823 - [DIP 1000] un-@safe code fails with dip1000
Summary: [DIP 1000] un-@safe code fails with dip1000
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, Vision
Depends on:
Blocks:
 
Reported: 2020-05-12 08:05 UTC by Juraj
Modified: 2022-07-26 07:57 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Juraj 2020-05-12 08:05:25 UTC
Adding -preview=dip1000 breaks code that is not annotated as @safe.


void boo(T)(T[] data, scope void delegate(T[] data) @nogc fun) {
	fun(data);
} 

void goo(T)(T[] data, /+scope+/ void delegate(T[] data) @nogc fun) {
	fun(data);
} 

int[256] arr;

void main() {
    void Execute(T)(T[] data) @nogc {
        // ...
    }  
    // Works
    goo(arr[0..$], &Execute!int);
    
    // Compiler error with DIP 1000
    boo(arr[0..$], &Execute!int);      
}

---
Error: template onlineapp.boo cannot deduce function from argument types !()(int[], void delegate(int[] data) pure nothrow @nogc @safe), candidates are:
onlineapp.d(2):        boo(T)(T[] data, scope void delegate(T[] data) @nogc fun)
---



https://run.dlang.io/is/mvYgJ9
Comment 1 Dennis 2021-07-11 23:52:51 UTC
Reduced a bit more:

```
void boo(T)(  scope   void delegate(T[] data) fun) {} 
void goo(T)(/+scope+/ void delegate(T[] data) fun) {} 

void main() {
    void Execute(int[] data) {}
    goo(&Execute); // Works
    boo(&Execute); // Compiler error with DIP 1000
}
```
Comment 2 Dlang Bot 2022-07-25 22:09:57 UTC
@dkorpel created dlang/dmd pull request #14331 "Fix 20823 - un-@safe code fails with dip1000" fixing this issue:

- Fix 20823 - un-@safe code fails with dip1000

https://github.com/dlang/dmd/pull/14331
Comment 3 Dlang Bot 2022-07-26 07:57:27 UTC
dlang/dmd pull request #14331 "Fix 20823 - un-@safe code fails with dip1000" was merged into master:

- bc49666578e6c40a73a0974a0a42186a5fbccd6e by Dennis Korpel:
  Fix 20823 - un-@safe code fails with dip1000

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