Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
comicsads opened this issue Aug 31, 2019 · 1 comment · May be fixed by #7
Open

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

comicsads opened this issue Aug 31, 2019 · 1 comment · May be fixed by #7

Comments

@comicsads
Copy link

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)
	}
}
@xyproto
Copy link

xyproto commented Aug 16, 2022

@comicsads This fork now supports time.Time and time.Duration, based on your suggestion, if it's any help.

The forked is used in my little editor o to make it possible to just type iferr on a single line to expand it into an if err != nil ... block.

Thanks for creating this project, @koron. 👍

@Jille Jille linked a pull request Sep 9, 2024 that will close this issue
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 a pull request may close this issue.

2 participants