Skip to content

fix(gnotypes): model interrealm v2 realm builtins#56

Open
tbruyelle wants to merge 1 commit into
gnoverse:mainfrom
tbruyelle:fix/interrealm-v2-realm-builtins
Open

fix(gnotypes): model interrealm v2 realm builtins#56
tbruyelle wants to merge 1 commit into
gnoverse:mainfrom
tbruyelle:fix/interrealm-v2-realm-builtins

Conversation

@tbruyelle

@tbruyelle tbruyelle commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

gnopls's embedded builtin universe still models the pre-interrealm-v2 semantics, so it mis-diagnoses valid gno (/r/) code:

  • cross is declared as var cross realm, so MyFunc(cross(cur), …) errors with "cannot call non-function cross".
  • the realm interface is missing the ACL predicates (IsUserCall, IsCurrent, …), so cur.IsUserCall() / cur.Previous().IsCurrent() report "undefined method", while it carries methods removed in v2 (Coins/Send/Origin).

Changes

Match the gno toolchain's authoritative gnobuiltins/gno0p9 definitions (from gnovm/pkg/gnolang/gotypecheck.go):

  • cross: var cross realmfunc cross(rlm realm) realm.
  • realm interface: add IsCode/IsUser/IsUserCall/IsUserRun/IsEphemeral/IsCurrent; drop Coins/Send/Origin.

Fix two latent loader bugs the cross-as-func change exposed:

  • builtin func signatures registered rawcross's realm param kept its package-qualified identity while the Universe realm was the cloned package-less type (identity mismatch). The signature is now cloned with the shared ctx so references resolve to the registered types.
  • *types.Named clone cached after recursion — a recursive self-reference (realm.Previous() realm) cloned a divergent, method-incomplete copy, so cur.Previous().IsUserCall() failed. The Named is now cached before recursing (NewNamed + SetUnderlying/AddMethod).

Tests

  • New TestGnoBuiltin subtests: cross call (cross(cur)), realm methods (all six predicates + recursive Previous().IsUserCall()).
  • Updated TestGnoBuiltinExporterVar from the old CrossingFunc(cross) value-form to CrossingFunc(cross(cur)).

go build ./..., go vet ./pkg/gnotypes/, and go test ./pkg/... ./internal/golang/... all pass.

Generated with 🤖 Claude

Update the embedded builtin universe to match the gno toolchain's
gnobuiltins/gno0p9 definitions, so gnopls type-checks interrealm v2
code the same way `gno test` does:

- cross: var -> func cross(rlm realm) realm, so cross(cur) calls
  type-check instead of erroring "cannot call non-function cross".
- realm interface: add the ACL predicates IsCode/IsUser/IsUserCall/
  IsUserRun/IsEphemeral/IsCurrent; drop the methods removed in v2
  (Coins/Send/Origin).

Fix two latent loader bugs the cross-as-func change exposed in
CloneTypeWithNilPackage / the builtin registration:

- builtin func signatures were registered raw, so cross's realm
  param kept its package-qualified identity while the Universe realm
  was the cloned package-less type (mismatch). Clone the signature
  with the shared ctx so references resolve to the registered types.
- the *types.Named clone cached the clone after recursing into the
  underlying type, so a recursive self-reference (realm.Previous()
  realm) cloned a divergent, method-incomplete copy. Cache the Named
  before recursing (NewNamed + SetUnderlying/AddMethod) so
  cur.Previous().IsUserCall() resolves.

Add regression subtests for cross(cur), the realm predicates, and the
recursive Previous() method call; update TestGnoBuiltinExporterVar to
the cross(cur) form.
@tbruyelle tbruyelle changed the title fix(gnotypes): model interrealm v2 (gno 0.9) realm builtins fix(gnotypes): model interrealm v2 realm builtins Jun 8, 2026
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.

1 participant