go-tree-sitter icon indicating copy to clipboard operation
go-tree-sitter copied to clipboard

Type of idx parameter in Child() and NamedChild() methods.

Open m-kru opened this issue 4 years ago • 3 comments

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)
}

m-kru avatar Oct 06 '21 12:10 m-kru

@smacker ping

m-kru avatar Jun 14 '22 11:06 m-kru

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.

smacker avatar Jun 14 '22 12:06 smacker

Well, the only reason is that they are never negative. However, I also understand your point on len and copy.

m-kru avatar Jun 15 '22 03:06 m-kru