Skip to content

Conversation

@doriable
Copy link
Member

This PR adds a zero test for the ir package, similar to
the one for the ast package to ensure that getters/accessors
on zero values return zero values and do not panic. It also fixes
panics on zero values.

Comment on lines +48 to +52
// node is a helper interface to enforce [id.Node] types.
type node[T any] interface {
zeroable
ID() id.ID[T]
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure if it's entirely necessary to enforce id.Nodes in this way.
Similarly, I'm not sure if it is necessary to enforce zeroable either, since *ir.File for example would not conform.

Comment on lines +17 to +19
testZeroAny[*ir.File](t)
testZeroAny[ir.Import](t) // Import embeds *ir.File
testZeroAny[*ir.Imports](t)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the question below, this currently doesn't test ir.Ref[T] for *ir.File and ir.Import. If we don't need to enforce the IsZero interface, and these are valid values for ir.Ref, then I can simplify this.

Comment on lines +575 to +580
// If the element is empty, this returns -1.
func (e Element) ValueNodeIndex() int {
if e.IsZero() {
return -1
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to make sure this behaviour is reasonable.

@doriable doriable requested a review from mcy December 24, 2025 00:08
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.

2 participants