Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type system hole: escaping inout delegates #17812

Open
dlangBugzillaToGithub opened this issue Aug 11, 2017 · 2 comments
Open

Type system hole: escaping inout delegates #17812

dlangBugzillaToGithub opened this issue Aug 11, 2017 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

timon.gehr reported this on 2017-08-11T15:36:42Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=17743

CC List

Description

DMD v.2075.0:

@safe:
int a;
immutable(int) b=2;

inout(int)* delegate(inout(int)*) dg;
inout(int)* prepare(inout(int)* x){
    dg = y=>x;
    return x;
}
void main(){
    prepare(&b);
    int* y=dg(&a);
    assert(&b is y); // passes. ouch.
    *y=3;
    assert(b is *&b); // fails!
}
@dlangBugzillaToGithub
Copy link
Author

schveiguy (@schveiguy) commented on 2017-08-14T13:32:14Z

This is why inout data is not allowed to be stored as a global (which essentially you have done). Basically, inout data should not be allowed to escape the function except via the parameters or return, where it is properly handled.

@dlangBugzillaToGithub
Copy link
Author

dfj1esp02 commented on 2021-12-13T13:36:57Z

As I understand, it's due to decision that nested functions use inout qialifier of the outer function. Then an easy way to fix this is to disallow conversion of such nested function to inout-typed delegate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant