Repository navigation
feat: map go and defer of interface method calls - #215
Merged
Merged
Conversation
A go or defer statement that calls a method of an interface value saves the interface value, then the arguments, and then checks the saved value with the new eo::nil_check. Go evaluates the arguments before it finds a nil interface and panics in the launching goroutine, so the check throws Go's nil dereference panic there, and the call is not launched or deferred. etcd raft's rafttest launches n.Step of an embedded raft.Node, and its tests defer n.Stop(). This freezes the interface-method part of #67. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
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.
Summary
This freezes
go i.M(args)anddefer i.M(args)whereiis an interface value. That is the interface-method part of #67.Go saves the interface value and evaluates the arguments. Only then does it find that the interface is nil, and it panics in the launching goroutine, so no goroutine starts and no call is deferred. The parity case checks that order: a counter that an argument increments is already incremented when
recoversees the panic.The translation follows the same order:
src/eo/interface.h: addseo::nil_check(const I&). For a nil interface value it throws Go's nil dereference panic, as a method call would.docs/GOROUTINE.md: adds an "Interface method calls" section, including the case of a method promoted from an embedded interface field. This form is removed from "Unfrozen launch forms".docs/TRANSLATION_RULES.md: adds the matching deferred form, witheo_defer_coused for a coroutine method. The not-covered lists are updated.tests/parity/interface_method_launch, which covers:goof a plain method and of a coroutine method, where the receiver and the arguments are captured before the variables change;deferof a plain method and of a coroutine method;goanddeferon a nil interface, recovered in the launcher, after the arguments are evaluated.etcd raft needs this. Its
rafttestpackage runsgo n.Step(ctx, m)on an embeddedraft.Node, and its tests rundefer n.Stop().Test plan
nil_checkfrom the nilgofails the case.nil_checkbefore the arguments in the nildeferfails the case.🤖 Generated with Claude Code
https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ