diff --git a/src/cmd/compile/internal/typecheck/expr.go b/src/cmd/compile/internal/typecheck/expr.go index 53d0cbf96d..83d1355fe5 100644 --- a/src/cmd/compile/internal/typecheck/expr.go +++ b/src/cmd/compile/internal/typecheck/expr.go @@ -8,6 +8,7 @@ import ( "fmt" "go/constant" "go/token" + "internal/types/errors" "strings" "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()) 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) diff --git a/test/fixedbugs/issue63333.go b/test/fixedbugs/issue63333.go new file mode 100644 index 0000000000..e14b367430 --- /dev/null +++ b/test/fixedbugs/issue63333.go @@ -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() {}