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: returning inout delegates #19300

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

Type system hole: returning inout delegates #19300

dlangBugzillaToGithub opened this issue Aug 11, 2017 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

timon.gehr reported this on 2017-08-11T15:41:13Z

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

CC List

Description

DMD v2.075.0:

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

inout(int)* delegate(inout(int)*)@safe delegate()@safe foo(inout(int)* y){
    inout(int)* bar(inout(int)* p){
        return y;
    }
    return ()=>&bar;
}
void main(){
    int* y=foo(&b)()(&a);
    *y=3;
    assert(&b is y); // passes. ouch.
    assert(b is *&b); // fails!
}

If &bar is returned directly instead of ()=>&bar, DMD applies a strange work-around (it replaces `inout` in the returned delegate by `const`).
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