Repository navigation
Description
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 rightThis 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?
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
[-]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[/+]feat(gnovm)!: let a package take the caller's realm as its first para…