griesemer / tryhard

tryhard finds and rewrites code suitable for try.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

false negative, possibly due to an else statement

josharian opened this issue · comments

This should be safe to transform:

			if err := dump(w, n, rec); err != nil {
				return err
			} else {
				fmt.Fprintln(w)
			}

to:

			try(dump(w, n, rec)
			fmt.Fprintln(w)

(The key restriction is that err does not appear in the else block.

Indeed. And if the assignment is using = instead of :=, it should be ok to transform even if err appears in the else block. Both these assume there are no aliases to err.

should we close

@codenoid Yes. Thanks for reminding me.

Closing this issue as "wontfix" since we have abandoned the try proposal.