mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: do not fatal when typechecking conversion expression
The types2 typechecker already reported all invalid conversions required by the Go language spec. However, the conversion involves go pragma is not specified in the spec, so is not checked by types2. Fixing this by handling the error gracefully during typecheck, just like how old typechecker did before CL 394575. Fixes #63333 Change-Id: I04c4121971c62d96f75ded1794ab4bdf3a6cd0ea Reviewed-on: https://go-review.googlesource.com/c/go/+/532515 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
62bdbd2596
commit
38db0316f4
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"go/constant"
|
"go/constant"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"internal/types/errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cmd/compile/internal/base"
|
"cmd/compile/internal/base"
|
||||||
@ -353,7 +354,10 @@ func tcConv(n *ir.ConvExpr) ir.Node {
|
|||||||
}
|
}
|
||||||
op, why := Convertop(n.X.Op() == ir.OLITERAL, t, n.Type())
|
op, why := Convertop(n.X.Op() == ir.OLITERAL, t, n.Type())
|
||||||
if op == ir.OXXX {
|
if op == ir.OXXX {
|
||||||
base.Fatalf("cannot convert %L to type %v%s", n.X, n.Type(), why)
|
// Due to //go:nointerface, we may be stricter than types2 here (#63333).
|
||||||
|
base.ErrorfAt(n.Pos(), errors.InvalidConversion, "cannot convert %L to type %v%s", n.X, n.Type(), why)
|
||||||
|
n.SetType(nil)
|
||||||
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
n.SetOp(op)
|
n.SetOp(op)
|
||||||
|
15
test/fixedbugs/issue63333.go
Normal file
15
test/fixedbugs/issue63333.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// errorcheck -goexperiment fieldtrack
|
||||||
|
|
||||||
|
// Copyright 2023 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
|
||||||
|
|
||||||
|
func f(interface{ m() }) {}
|
||||||
|
func g() { f(new(T)) } // ERROR "m method is marked 'nointerface'"
|
||||||
|
|
||||||
|
type T struct{}
|
||||||
|
|
||||||
|
//go:nointerface
|
||||||
|
func (*T) m() {}
|
Loading…
x
Reference in New Issue
Block a user