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

Error comparisons in templates not working until 1.14 #39108

Closed
timlind opened this issue May 16, 2020 · 3 comments
Closed

Error comparisons in templates not working until 1.14 #39108

timlind opened this issue May 16, 2020 · 3 comments

Comments

@timlind
Copy link

timlind commented May 16, 2020

What version of Go are you using (go version)?

$ go version
1.13

Does this issue reproduce with the latest release?

No.

What operating system and processor architecture are you using (go env)?

This is erroring on google app engine 1.13 and locally on 1.13, but not on 1.14

go env Output
$ go env

What did you do?

data := struct{
   Errors []error
   KnownErrors map[string]error
}{
   []error{ErrEmailExists},
   map[string]error{ErrEmailExists}
}

template.Execute(w, data)

{{range .Errors}}
{{if eq . $.KnownErrors.ErrEmailExists}}
Already registered.
{{end}}
{{end}}

What did you expect to see?

Already registered.

What did you see instead?

error calling eq: invalid type for comparison

@ALTree
Copy link
Member

ALTree commented May 16, 2020

This is expected. A proposal to make eq support all comparable types (#33740) was accepted -and the fix merged- for Go1.14. So it won't work in go1.13, but it does on 1.14.

I don't think the change qualifies for a backport (we only backport fixes for serious security issues or problems with no workaround), so I'm not sure there's anything else left to do. I'm closing this issue as Working As Intended, but feel free to comment if you disagree.

@ALTree ALTree closed this as completed May 16, 2020
@timlind
Copy link
Author

timlind commented May 16, 2020

Maybe some pointers to a workaround if there is one? Even trying to call and compare Error seemed to fail.

@timlind
Copy link
Author

timlind commented May 16, 2020

Ok, just tried it out on a playground and .Error comparisons work fine.

@golang golang locked and limited conversation to collaborators May 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants