-
Notifications
You must be signed in to change notification settings - Fork 18k
text/template: fix truth handling of typed interface nils in if and with #30534
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
Conversation
This PR (HEAD: d8d8c03) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/164958 to see it. Tip: You can toggle comments from me using the |
Message from Gobot Gobot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Daniel Martí: Patch Set 2: We don't use markdown in commit messages; see https://github.com/golang/go/wiki/CommitMessage Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 3: Commit message was updated. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 3:
I assume that was the code fence wrappers (now removed); I assume backticks around identifiers (e.g. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 5: Commit message was updated. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Before this commit, the two logically equivalent conditionals below would produce different output: {{ if not .NonEmptyInterfaceTypedNil }}OK{{ else }}{{ end }} {{ if .NonEmptyInterfaceTypedNil }}{{ else }}OK{{ end }} The functions `not`, `or`, and `and` all use the same `truth` function, which unwraps any concrete interface value before passing it to `isTrue`. `if` and `with` also use `isTrue` to establish truth, but was missing the interface indirect call. Fixes golang#30501
This PR (HEAD: 95fc2c8) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/164958 to see it. Tip: You can toggle comments from me using the |
Message from Bjørn Erik Pedersen: Patch Set 7:
Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Daniel Martí: Patch Set 7: The commit message is still like it was initially, unless I've missed something? Remember that if you're using the PR bot, you must make all changes through the PR. It ignores commit messages; you must modify the PR title and description. I know that's cumbersome, which is why I'd just send a CL directly. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 8: Commit message was updated. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 10: Commit message was updated. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 11:
I tried both, but it seems to be reverted ... I will have to read up on the Gerrit documentation tomorrow, the section about how to edit the commit message ... Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Daniel Martí: Patch Set 11: Please note what I mentioned earlier; you must modify the PR body, i.e. the top comment's content. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 11:
Yes, I understand that. I have done that several times, but the change gets reverted. I suppose it is this issue: Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Daniel Martí: Patch Set 12: Seems to work fine for me :) See my edit on the PR content. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Dmitri Shuralyov: Patch Set 11:
I see a total of two edits on the PR body: https://user-images.githubusercontent.com/1924134/53703193-0d32a380-3ddd-11e9-8aea-6b0c86cc3dc2.png Neither of those were reverted as far as I can see. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 13:
OK, I got it now. The "PR body" referred to the original GitHub PR. I edited the commit message here in the Gerrit UI, which got reverted. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Dmitri Shuralyov: Patch Set 14:
Do you think we can improve the wording in the documentation (i.e., go/.github/PULL_REQUEST_TEMPLATE Lines 1 to 3 in 4fb900e
Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Daniel Martí: Patch Set 14: (3 comments) This makes sense to me, in theory. There are no comments about explicitly avoiding indirectInterface in if/with, and there are no tests locking the old behavior, so perhaps this was just due to human error. I also tend to agree that this change makes text/template more consistent. Inside a template, all values are evaluated behind interface{}, so it's easy for nil pointers to suddenly gain a type and become non-nil when automatically translated to an interface. On the other hand, it seems like text/template has behaved this way for a long time; at least since 2011, from what I can tell. There's a good chance that some template out there will suddenly change behavior, so this would need to be submitted early and contain a clear changelog entry for 1.13. Adding Rob and Roger for a second opinion, but I think we can give this a go for 1.13. Worst case, if it turns out that this behavior was on purpose, or that it broke too many programs, we can revert and consider other options. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Bjørn Erik Pedersen: Patch Set 15: (3 comments) Friendly bump. To me this is an obvious fix, but what do I know. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Russ Cox: Patch Set 15: Code-Review+2 Looked at with Rob. +2 Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Russ Cox: Patch Set 15: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Gobot Gobot: Patch Set 15: TryBots beginning. Status page: https://farmer.golang.org/try?commit=abc6b648 Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Gobot Gobot: Patch Set 15: Build is still in progress... Other builds still in progress; subsequent failure notices suppressed until final report. Consult https://build.golang.org/ to see whether they are new failures. Keep in mind that TryBots currently test exactly your git commit, without rebasing. If your commit's git parent is old, the failure might've already been fixed. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Message from Gobot Gobot: Patch Set 15: TryBot-Result-1 1 of 19 TryBots failed: Consult https://build.golang.org/ to see whether they are new failures. Keep in mind that TryBots currently test exactly your git commit, without rebasing. If your commit's git parent is old, the failure might've already been fixed. Please don’t reply on this GitHub thread. Visit golang.org/cl/164958. |
Before this commit, the two logically equivalent conditionals below would produce different output: {{ if not .NonEmptyInterfaceTypedNil }}OK{{ else }}{{ end }} {{ if .NonEmptyInterfaceTypedNil }}{{ else }}OK{{ end }} The functions `not`, `or`, and `and` all use the same `truth` function, which unwraps any concrete interface value before passing it to `isTrue`. `if` and `with` also use `isTrue` to establish truth, but was missing the interface indirect call. Fixes #30501 Change-Id: I9c49eed41e737d8f162e39bef1c3b82fd5518fed GitHub-Last-Rev: 95fc2c8 GitHub-Pull-Request: #30534 Reviewed-on: https://go-review.googlesource.com/c/go/+/164958 Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]>
This PR is being closed because golang.org/cl/164958 has been merged. |
Before this commit, the two logically equivalent conditionals below would produce different output: {{ if not .NonEmptyInterfaceTypedNil }}OK{{ else }}{{ end }} {{ if .NonEmptyInterfaceTypedNil }}{{ else }}OK{{ end }} The functions `not`, `or`, and `and` all use the same `truth` function, which unwraps any concrete interface value before passing it to `isTrue`. `if` and `with` also use `isTrue` to establish truth, but was missing the interface indirect call. Fixes #30501 Change-Id: I9c49eed41e737d8f162e39bef1c3b82fd5518fed GitHub-Last-Rev: 95fc2c82f26d24a457de4deaa7e5756718fbf07c GitHub-Pull-Request: golang/go#30534 Reviewed-on: https://go-review.googlesource.com/c/go/+/164958 Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]>
Before this commit, the two logically equivalent conditionals below would
produce different output:
The functions
not
,or
, andand
all use the sametruth
function, whichunwraps any concrete interface value before passing it to
isTrue
.if
andwith
also useisTrue
to establish truth, but was missing theinterface indirect call.
Fixes #30501