fix(gnotypes): model interrealm v2 realm builtins#56
Open
tbruyelle wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
gnopls's embedded builtin universe still models the pre-interrealm-v2 semantics, so it mis-diagnoses valid gno (
/r/) code:crossis declared asvar cross realm, soMyFunc(cross(cur), …)errors with "cannot call non-function cross".realminterface is missing the ACL predicates (IsUserCall,IsCurrent, …), socur.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/gno0p9definitions (fromgnovm/pkg/gnolang/gotypecheck.go):cross:var cross realm→func cross(rlm realm) realm.realminterface: addIsCode/IsUser/IsUserCall/IsUserRun/IsEphemeral/IsCurrent; dropCoins/Send/Origin.Fix two latent loader bugs the cross-as-func change exposed:
cross'srealmparam kept its package-qualified identity while the Universerealmwas the cloned package-less type (identity mismatch). The signature is now cloned with the sharedctxso references resolve to the registered types.*types.Namedclone cached after recursion — a recursive self-reference (realm.Previous() realm) cloned a divergent, method-incomplete copy, socur.Previous().IsUserCall()failed. TheNamedis now cached before recursing (NewNamed+SetUnderlying/AddMethod).Tests
TestGnoBuiltinsubtests:cross call(cross(cur)),realm methods(all six predicates + recursivePrevious().IsUserCall()).TestGnoBuiltinExporterVarfrom the oldCrossingFunc(cross)value-form toCrossingFunc(cross(cur)).go build ./...,go vet ./pkg/gnotypes/, andgo test ./pkg/... ./internal/golang/...all pass.Generated with 🤖 Claude