go-tree-sitter
go-tree-sitter copied to clipboard
Type of idx parameter in Child() and NamedChild() methods.
Child() and NamedChiled() parameters are currently int. Shouldn't they be of type uint32?
// Child returns the node's child at the given index, where zero represents the first child.
func (n Node) Child(idx int) *Node {
nn := C.ts_node_child(n.c, C.uint32_t(idx))
return n.t.cachedNode(nn)
}
// NamedChild returns the node's *named* child at the given index.
func (n Node) NamedChild(idx int) *Node {
nn := C.ts_node_named_child(n.c, C.uint32_t(idx))
return n.t.cachedNode(nn)
}
@smacker ping
hi @m-kru ! Is there any particular reason you need it to be unit32?
Int type is at least 32 bytes.
I chose to use int instead of unit32 here because it is the most common integer type in Go according to my experience and is normally used for indexing. Build-in functions such as len or copy also operate with int type which allows to avoid type conversion.
Well, the only reason is that they are never negative. However, I also understand your point on len and copy.