Skip to content

Incorrect return values for time.Time and time.Duration #4

@comicsads

Description

@comicsads

Attempting to use iferr on a function which returns a value of either time.Time or time.Duration results in attempting to return a nil value.

func returnTime() time.Time {
	if err != nil {
		return nil
	}
}

func returnDur() time.Duration {
	if err != nil {
		return nil
	}
}

This is not correct, and will result in an error at compile time. What should instead be returned is this

func returnTime() time.Time {
	if err != nil {
		return time.Time{}
	}
}

func returnDur() time.Duration {
	if err != nil {
		return time.Duration(0)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions