-
-
Notifications
You must be signed in to change notification settings - Fork 676
fix Issue 18143 - in/out contracts should be implicitly 'this' const #7553
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -885,7 +885,6 @@ private extern(C++) final class Semantic3Visitor : Visitor | |
| sc2.flags = (sc2.flags & ~SCOPEcontract) | SCOPErequire; | ||
|
|
||
| // BUG: need to error if accessing out parameters | ||
| // BUG: need to treat parameters as const | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. This PR seems to only disable writing to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, ok. Nevermind then. :-) I was just confused because deleting this comment in this PR makes it seem like this PR is fixing the entire issue. I suppose making |
||
| // BUG: need to disallow returns and throws | ||
| // BUG: verify that all in and ref parameters are read | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment as seen today appeared in D1.011. Before it used to be: Which has been here since the dawn of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to allude to this: But I don't think that any of those are a compiler bug at all, and so this comment should be removed. @WalterBright do I understand the context correctly?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should an error be emitted if a parameter isn't read in the in-contract? How else would you express that any possible value is permitted for that parameter?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some languages enforce that some parameter are used, e.g. C# forces you to assign
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm saying I don't think it should be considered as a bug. Also the comments doesn't say anything about all parameters. Just
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It may also be implying that all input parameters should actually be used in the implementation. |
||
| freq = freq.statementSemantic(sc2); | ||
|
|
@@ -908,7 +907,6 @@ private extern(C++) final class Semantic3Visitor : Visitor | |
| sc2 = scout; //push | ||
| sc2.flags = (sc2.flags & ~SCOPEcontract) | SCOPEensure; | ||
|
|
||
| // BUG: need to treat parameters as const | ||
| // BUG: need to disallow returns and throws | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't document bugs in the source code like this, they should be in Bugzilla:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't verify any of the comments, so no idea what the state is. |
||
|
|
||
| if (funcdecl.fensure && f.next.ty != Tvoid) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/fail18143.d(20): Error: variable fail18143.S.a cannot modify parameter 'this' in contract | ||
| fail_compilation/fail18143.d(21): Error: variable fail18143.S.a cannot modify parameter 'this' in contract | ||
| fail_compilation/fail18143.d(25): Error: variable fail18143.S.a cannot modify parameter 'this' in contract | ||
| fail_compilation/fail18143.d(26): Error: variable fail18143.S.a cannot modify parameter 'this' in contract | ||
| fail_compilation/fail18143.d(35): Error: variable fail18143.C.a cannot modify parameter 'this' in contract | ||
| fail_compilation/fail18143.d(36): Error: variable fail18143.C.a cannot modify parameter 'this' in contract | ||
| fail_compilation/fail18143.d(40): Error: variable fail18143.C.a cannot modify parameter 'this' in contract | ||
| fail_compilation/fail18143.d(41): Error: variable fail18143.C.a cannot modify parameter 'this' in contract | ||
| --- | ||
| */ | ||
|
|
||
| struct S | ||
| { | ||
| int a; | ||
|
|
||
| this(int n) | ||
| in { a = n; } // error, modifying this.a in contract | ||
| out { a = n; } // error, modifying this.a in contract | ||
| do { } | ||
|
|
||
| void foo(int n) | ||
| in { a = n; } // error, modifying this.a in contract | ||
| out { a = n; } // error, modifying this.a in contract | ||
| do { } | ||
| } | ||
|
|
||
| class C | ||
| { | ||
| int a; | ||
|
|
||
| this(int n) | ||
| in { a = n; } // error, modifying this.a in contract | ||
| out { a = n; } // error, modifying this.a in contract | ||
| do { } | ||
|
|
||
| void foo(int n) | ||
| in { a = n; } // error, modifying this.a in contract | ||
| out { a = n; } // error, modifying this.a in contract | ||
| do { } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this already forbidden?
https://run.dlang.io/is/NacqYo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is that accessing the
outparameter, oroutparameters?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I've worked out what this means:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://issues.dlang.org/show_bug.cgi?id=18203