ecs icon indicating copy to clipboard operation
ecs copied to clipboard

Inaccessible error condition

Open inhies opened this issue 6 years ago • 0 comments

I believe the if !ok check in the bottom of this snippet is inaccessible and therfore not required, due to the check for entity.tag.matches(tag) prior to it. I cannot come up with a situation in which the first tag check would pass but the attempt to get component data would fail. Is this correct? Code inserted below for your reference:

func (manager *Manager) fetchComponentsForEntity(entity *Entity, tag Tag) map[*Component]interface{} {

	if !entity.tag.matches(tag) {
		return nil
	}

	componentMap := make(map[*Component]interface{})

	for _, component := range manager.components {
		if tag.matches(component.tag) {
			data, ok := entity.GetComponentData(component)
			if !ok {
				return nil // if one of the required components is not set, return nothing !
			}```

inhies avatar Jun 02 '19 14:06 inhies