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

fix Issue 22541 - DIP1000: Resolve ambiguity of ref-return-scope para… #13677

Merged
merged 1 commit into from Feb 17, 2022

Conversation

WalterBright
Copy link
Member

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Auto-close Bugzilla Severity Description
22541 enhancement DIP1000: Resolve ambiguity of ref-return-scope parameters

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#13677"

@thewilsonator
Copy link
Contributor

Should this target stable?

@WalterBright
Copy link
Member Author

I'd rather not. It could be a disruptive change.

@dlang-bot dlang-bot merged commit 2b3cd5d into dlang:master Feb 17, 2022
@WalterBright WalterBright deleted the fix22541-c7 branch February 17, 2022 06:22
int i;
int* ptr;

int* wannabeReturnRef() scope return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be marked @safe

@maxhaton
Copy link
Member

@dkorpel @WalterBright Should this have a changelog

@dkorpel
Copy link
Contributor

dkorpel commented Feb 17, 2022

It already has a changelog: https://dlang.org/changelog/2.099.0.html#22541
It just needs a correct implementation still 🙂

This patch makes the compiler accept the function definition, but on a function call it still thinks it's return scope allowing you to escape the data. The problem also still persists with actual ref parameters, here's a bigger test case:

struct S
{
    int i;
    int* ptr;

    int* wannabeReturnRef() scope return @safe
    {
        return &i;
    }
}

int* wannabeReturnRefFree(scope return ref S s) @safe
{
	return &s.i; // should be accepted
}

int* gPtr;
void main() @safe 
{
	S s;
	gPtr = s.wannabeReturnRef(); // should be rejected
	gPtr = s.wannabeReturnRefFree(); // should be rejected
}

@maxhaton
Copy link
Member

@dkorpel I think that changelog is very poor.

@dkorpel
Copy link
Contributor

dkorpel commented Feb 17, 2022

@dkorpel I think that changelog is very poor.

It is, should we remove it until it's actually implemented correctly, or expand it but also add a footnote that the implementation isn't ready?

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