OLITERAL isn't always ConstExpr. It can also be BasicLit or Name.
Change-Id: I44d595830f9e206eccf6fb37bd47ddf957db0866
Reviewed-on: https://go-review.googlesource.com/c/go/+/526277
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
func isLiteral(n ir.Node) (constant.Value, bool) {
sv := ir.StaticValue(n)
- if sv.Op() == ir.ONIL {
+ switch sv.Op() {
+ case ir.ONIL:
return nil, true
+ case ir.OLITERAL:
+ return sv.Val(), true
}
- if sv.Op() != ir.OLITERAL {
- return nil, false
- }
- ce := sv.(*ir.ConstExpr)
- return ce.Val(), true
+ return nil, false
}
// isSameLiteral checks to see if 'v1' and 'v2' correspond to the same