Enforce payable vs non-payable constructors#458
Merged
Conversation
14d4efd to
11de758
Compare
Contributor
Author
|
Rebased after comptime. |
11de758 to
f81d935
Compare
mbenke
approved these changes
Jun 12, 2026
Comment on lines
+162
to
+171
| else if (expectedStatus == "success") | ||
| { | ||
| if (!status) | ||
| { | ||
| std::cerr << "Expected creation success but got failure" << std::endl; | ||
| resultRecorder.record(filename, "Expected constructor status success but got failure.", "failure", expectedStatus, gasUsed, gasUsedForDeposit); | ||
| hasTestFailure = true; | ||
| continue; | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
what if expected status is not one of ["failure","success"] (e.g. typo)?
Contributor
Author
There was a problem hiding this comment.
This is mostly a code duplication of the non-constructor part below. I can add an error in both cases.
| text "constructor" | ||
| ppr (Constructor ps bd payable) = | ||
| (if payable then text "payable" else empty) | ||
| <+> text "constructor" |
Collaborator
There was a problem hiding this comment.
This introduces an extra space if not payable
Suggested change
| <+> text "constructor" | |
| if payable then text "payable" <+> text "constructor" else text "constructor" |
Contributor
Author
There was a problem hiding this comment.
Is it better two have two tokens, than one text "payable constructor" ?
Comment on lines
+164
to
+165
| (if payable then text "payable" else empty) | ||
| <+> text "constructor" |
Collaborator
There was a problem hiding this comment.
This introduces an extra space if not payable
Suggested change
| (if payable then text "payable" else empty) | |
| <+> text "constructor" | |
| if payable then text "payable" <+> text "constructor" else text "constructor" |
Contributor
Author
|
@mbenke pushed the fixes |
Constructors can now be marked `payable`. A non-payable constructor (the default) rejects any incoming value transfer at deploy time, reverting with the same NonPayableReceivedValue error (0xb5988ea3) used by the runtime method-level callvalue check. A payable constructor accepts value. - Add `constrPayable` to the surface and resolved Constructor AST - Parse `payable constructor(...)` (backtrack so `payable function/fallback` still parse) - Emit a NonPayable callvalue check in the generated deployer for non-payable constructors - Pretty-print the `payable` modifier - Let constructor tests assert an expected outcome (status/returndata); absent "output" still means "expect success" - Add payable_ctor / nonpayable_ctor dispatch tests and assert the existing PayableTest constructor accepts zero value Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
1e483f1 to
352e79a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Constructors can now be marked
payable. A non-payable constructor (the default) rejects any incoming value transfer at deploy time, reverting with the same NonPayableReceivedValue error (0xb5988ea3) used by the runtime method-level callvalue check. A payable constructor accepts value.constrPayableto the surface and resolved Constructor ASTpayable constructor(...)(backtrack sopayable function/fallbackstill parse)payablemodifier