Skip to content

Restrict payable to contract functions/fallback#461

Merged
mbenke merged 1 commit into
argotorg:mainfrom
axic:toplevel-payable
Jun 15, 2026
Merged

Restrict payable to contract functions/fallback#461
mbenke merged 1 commit into
argotorg:mainfrom
axic:toplevel-payable

Conversation

@axic

@axic axic commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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.

@axic axic force-pushed the toplevel-payable branch from 0d76819 to b0f4075 Compare June 12, 2026 13:51
-- 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

@axic axic Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@axic axic force-pushed the toplevel-payable branch 2 times, most recently from 0534200 to 7dd1e59 Compare June 12, 2026 14:48
…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>
@axic axic force-pushed the toplevel-payable branch from 7dd1e59 to d4280bb Compare June 12, 2026 14:53

@mbenke mbenke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well done

@mbenke mbenke merged commit 03ad490 into argotorg:main Jun 15, 2026
4 checks passed
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.

3 participants