aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/printer.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2018-03-29 18:22:23 -0700
committerRobert Griesemer <gri@golang.org>2018-04-03 05:34:20 +0000
commitc65a2781be7a8029435ea3d6a3c54c601ac4ba3e (patch)
treeb7017c568143e1aca93a23af43603da4209e9be8 /src/cmd/compile/internal/syntax/printer.go
parent071f0de4ec0d912b2908821466818ca2be04655c (diff)
downloadgo-c65a2781be7a8029435ea3d6a3c54c601ac4ba3e.tar.gz
go-c65a2781be7a8029435ea3d6a3c54c601ac4ba3e.zip
cmd/compile: better handling of incorrect type switches
Don't report errors if we don't have a correct type switch guard; instead ignore it and leave it to the type-checker to report the error. This leads to better error messages concentrating on the type switch guard rather than errors around (confusing) syntactic details. Also clean up some code setting up AssertExpr (they never have a nil Type field) and remove some incorrect TODOs. Fixes #24470. Change-Id: I69512f36e0417e3b5ea9c8856768e04b19d654a8 Reviewed-on: https://go-review.googlesource.com/103615 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/printer.go')
-rw-r--r--src/cmd/compile/internal/syntax/printer.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/syntax/printer.go b/src/cmd/compile/internal/syntax/printer.go
index f4c2b6dde6..8ff3bfa794 100644
--- a/src/cmd/compile/internal/syntax/printer.go
+++ b/src/cmd/compile/internal/syntax/printer.go
@@ -393,13 +393,13 @@ func (p *printer) printRawNode(n Node) {
p.print(_Rbrack)
case *AssertExpr:
- p.print(n.X, _Dot, _Lparen)
- if n.Type != nil {
- p.printNode(n.Type)
- } else {
- p.print(_Type)
+ p.print(n.X, _Dot, _Lparen, n.Type, _Rparen)
+
+ case *TypeSwitchGuard:
+ if n.Lhs != nil {
+ p.print(n.Lhs, blank, _Define, blank)
}
- p.print(_Rparen)
+ p.print(n.X, _Dot, _Lparen, _Type, _Rparen)
case *CallExpr:
p.print(n.Fun, _Lparen)
@@ -557,12 +557,6 @@ func (p *printer) printRawNode(n Node) {
}
p.printSwitchBody(n.Body)
- case *TypeSwitchGuard:
- if n.Lhs != nil {
- p.print(n.Lhs, blank, _Define, blank)
- }
- p.print(n.X, _Dot, _Lparen, _Type, _Rparen)
-
case *SelectStmt:
p.print(_Select, blank) // for now
p.printSelectBody(n.Body)