Skip to content

Conversation

@WalterBright
Copy link
Member

No description provided.

{
int b;
return foo6(&b);
}
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is not related, according to the P.R.'s title ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we need to review #6321 first.

struct S7
{
int[10] a;
int[3] abc(int i)
Copy link
Member

Choose a reason for hiding this comment

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

This function is not @safe, hence scope is not enforced here. I got bit by this many times, hence why I so strongly argued for scope being enforced everywhere.

I would also add the following test cases:

int[3] test1 (scope int[] p) @safe { return p[0 .. 3]; }             // Do not error because there isn't any indirection
char*[3] test1 (scope char*[] p) @safe { return p[0 .. 3]; }   // Error here because there is an indirection

Copy link
Member

Choose a reason for hiding this comment

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

Would it change the design to extend scope checks (without scope inference) to unsafe code later on?
If not we could defer this decision and discussion.
Added it to the scope/DIP1000 backlog https://trello.com/c/XT4RECah/96-spec-how-to-extend-scope-checks-to-unsafe-code.

Copy link
Member Author

Choose a reason for hiding this comment

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

int[3] test1 (scope int[] p) @safe { return p[0 .. 3]; }             // Do not error because there isn't any indirection

added

char*[3] test1 (scope char*[] p) @safe { return p[0 .. 3]; }   // Error here because there is an indirection

scope is not transitive, so the indirection is not covered by it.

Copy link
Contributor

Choose a reason for hiding this comment

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

scope is not transitive, so the indirection is not covered by it.

So this should not error ? If so, please add the test case as well.
Also, abc is still missing @safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

So this should not error ?

That's right.

If so, please add the test case as well. Also, abc is still missing @safe.

done

@MartinNowak MartinNowak merged commit fbbfce8 into dlang:scope Dec 16, 2016
@WalterBright WalterBright deleted the static-array branch December 17, 2016 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants