Skip to content

gnovm: a /p/ package can't take a realm as its only/first parameter #5786

Open

Description

@davd-gzl

A function or method whose first parameter is a realm is treated as a "crossing function", and crossing functions are rejected outside /r/ realms. So a /p/ package can't declare a helper that simply takes the current realm:

package realmbug // gno.land/p/demo/realmbug — a /p/ package

func Sync(rlm realm) {}            // ❌ first realm argument must have name `cur`
func Sync(cur realm) {}            // ❌ crossing function declared in non-realm package

type S struct{}
func (s *S) Sync(rlm realm) {}     // ❌ same — the receiver doesn't make realm "non-first"

The only way to compile is to push the realm out of first position with a throwaway param:

func Sync(_ struct{}, rlm realm) {} // ✅ compiles, but that junk arg can't be right

This was normal, intended behavior before. Under the old design packages never crossed, so a realm-first signature in /p/ was always a mistake, and rejecting it was correct. The new interrealm design is what shifts it: now that packages legitimately cross, the same rule blocks a valid pattern and forces the junk-param workaround.

daokit's interrealm-v2 port (samouraiworld/gnodaokit#64) is a real example: it threads a realm through /p/ package code but has to keep it out of first position everywhere, e.g. Execute(id uint64, rlm realm) and New(conf *Config, rlm realm), naming it rlm per the reserved-name rule. Where the realm is the only thing a call needs, it's a genuine helper that can't be written as func(rlm realm).

Where it comes from

FuncType.IsCrossing() (types.go:1382) keys purely off the first parameter's type and ignores the receiver, and crossingAllowed() (preprocess.go:4499) rejects crossing functions outside /r/ realms (with carve-outs for *_test.gno and ephemeral main).

Repro

(needs Go, ~1 min)

mkdir realmbug && cd realmbug
printf 'module = "gno.land/p/demo/realmbug"\ngno = "0.9"\n' > gnomod.toml
printf 'package realmbug\n\nfunc Sync(rlm realm) {}\n' > bug.gno
go run github.com/gnolang/gno/gnovm/cmd/gno@master lint .

Question

Now that packages can cross, should a /p/ package be allowed a realm as its sole/first arg (named e.g. rlm, non-crossing), or is the junk-leading-param still the intended workaround?

Activity

  1. changed the title [-]gno: a `/p/` package can't take a `realm` as its only/first parameter[/-] [+]gnovm: a `/p/` package can't take a `realm` as its only/first parameter[/+] on Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    📦 🤖 gnovmIssues or PRs gnovm related🐞 bugSomething isn't working

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions