Skip to content

Add public visibility modifier for contract functions#434

Open
axic wants to merge 3 commits into
argotorg:mainfrom
axic:public-dispatch
Open

Add public visibility modifier for contract functions#434
axic wants to merge 3 commits into
argotorg:mainfrom
axic:public-dispatch

Conversation

@axic

@axic axic commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

In a contract every function is private, unless marked as public. Special cases: constructor and fallback are always considered public, but the keyword is not needed to be present (if fact it can't be).

@axic

axic commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

I'll rebase this once fallback is merged.

@axic axic force-pushed the public-dispatch branch 2 times, most recently from 6f89ae4 to b1e0716 Compare June 8, 2026 12:48
@axic

axic commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@rodrigogribeiro @mbenke this should be ready now

claude and others added 3 commits June 8, 2026 15:11
Functions in a contract are now private by default; only those marked
with the new `public` keyword preceding `function` are exposed through
the runtime dispatcher (and get a generated `SigString` instance).

- `FunDef` carries a `funIsPublic :: Bool` field threaded through
  parsing, name resolution, type inference, specialisation and
  pretty-printing.
- Parser accepts an optional `public` keyword before `function`;
  `public` is now a reserved word.
- `ContractDispatch` filters the dispatch method tuple and selector
  data types to public functions only.

Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
Updates every `.solc` test fixture (and example std imports) so each
function defined inside a `contract { ... }` block is prefixed with
the new `public` keyword. Top-level functions, class methods, and
instance methods are left untouched since the visibility modifier
only applies to contract members.

Also adds a `hidden()` non-public method to dispatch/basic.solc and a
corresponding basic.json test case verifying its selector (aef6d4b1)
falls through to the missing-fallback error (4924aef0) instead of
being dispatched.
Both are implicitly public — the dispatch entry point always invokes them,
so writing `public fallback()` or `public constructor()` is misleading.
Detect this in the contract-declaration parser and emit a clear error
instead of the confusing parse failure that came out before.

Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
@axic axic force-pushed the public-dispatch branch from 0028686 to 6d8310f Compare June 8, 2026 13:11
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.

2 participants