mirror of
https://github.com/golang/go.git
synced 2025-11-10 13:41:05 +00:00
[dev.regabi] cmd/compile: use '%q' for printing rune values less than 128
Fixes #43762 Change-Id: I51734c9b4ee2366a5dae53b2d27b363f4d5fe6c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/284592 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
a2f825c542
commit
9423d50d53
2 changed files with 18 additions and 7 deletions
|
|
@ -589,20 +589,20 @@ func exprFmt(n Node, s fmt.State, prec int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Type() == types.UntypedRune {
|
if n.Type() == types.UntypedRune {
|
||||||
switch x, ok := constant.Int64Val(n.Val()); {
|
switch x, ok := constant.Uint64Val(n.Val()); {
|
||||||
case !ok:
|
case !ok:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(s, "('\\x00' + %v)", n.Val())
|
fmt.Fprintf(s, "('\\x00' + %v)", n.Val())
|
||||||
|
|
||||||
case ' ' <= x && x < utf8.RuneSelf && x != '\\' && x != '\'':
|
case x < utf8.RuneSelf:
|
||||||
fmt.Fprintf(s, "'%c'", int(x))
|
fmt.Fprintf(s, "%q", x)
|
||||||
|
|
||||||
case 0 <= x && x < 1<<16:
|
case x < 1<<16:
|
||||||
fmt.Fprintf(s, "'\\u%04x'", uint(int(x)))
|
fmt.Fprintf(s, "'\\u%04x'", x)
|
||||||
|
|
||||||
case 0 <= x && x <= utf8.MaxRune:
|
case x <= utf8.MaxRune:
|
||||||
fmt.Fprintf(s, "'\\U%08x'", uint64(x))
|
fmt.Fprintf(s, "'\\U%08x'", x)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprint(s, types.FmtConst(n.Val(), s.Flag('#')))
|
fmt.Fprint(s, types.FmtConst(n.Val(), s.Flag('#')))
|
||||||
|
|
|
||||||
11
test/fixedbugs/issue43762.go
Normal file
11
test/fixedbugs/issue43762.go
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
// errorcheck
|
||||||
|
|
||||||
|
// Copyright 2021 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package p
|
||||||
|
|
||||||
|
var _ = true == '\\' // ERROR "invalid operation: true == '\\\\'"
|
||||||
|
var _ = true == '\'' // ERROR "invalid operation: true == '\\''"
|
||||||
|
var _ = true == '\n' // ERROR "invalid operation: true == '\\n'"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue