Restrict payable to contract functions/fallback#461
Merged
Conversation
axic
commented
Jun 12, 2026
| -- of a confusing generic parse failure. Each branch commits (consumes the | ||
| -- keyword) before failing, so the surrounding 'choice' does not fall through | ||
| -- to the function/class/instance parser. | ||
| contractOnlyDeclP :: Parser TopDecl |
Contributor
Author
There was a problem hiding this comment.
These just provide a nicer error message, not strictly neccesary.
Before:
<input>:8:1:
|
8 | constructor() {}
| ^
unexpected 'c'
expecting "class", "contract", "data", "default", "export", "forall", "function", "import", "instance", "payable", "pragma", "type", or end of input
After:
<input>:8:12:
|
8 | constructor() -> () {}
| ^
a `constructor` may only be declared inside a contract
0534200 to
7dd1e59
Compare
…ructor/fallback to contracts `payable` was accepted on any function signature, including top-level functions, class signatures, and instance methods. Thread an `allowPayable` flag through signatureP/funDefAfterPrefix so it is only accepted on a function or fallback inside a `contract`; elsewhere it fails with a clear message. `constructor` and `fallback` are only wired into contract bodies, but writing them at the top level produced a confusing generic parse error. Add an explicit top-level guard that rejects them with a clear "only inside a contract" message. Add expect-failure fixtures for top-level payable function, top-level constructor, and top-level fallback. Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
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.
payablewas accepted on any function signature, including top-level functions, class signatures, and instance methods. Thread anallowPayableflag through signatureP/funDefAfterPrefix so it is only accepted on a function or fallback inside acontract; elsewhere it fails with a clear message.constructorandfallbackare only wired into contract bodies, but writing them at the top level produced a confusing generic parse error. Add an explicit top-level guard that rejects them with a clear "only inside a contract" message.Add expect-failure fixtures for top-level payable function, top-level constructor, and top-level fallback.