From ea51e92c8a76ef476d99973468d755df5ab5ee0d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 6 Jun 2023 18:46:29 -0700 Subject: [PATCH] go/types, types2: don't crash when using trace with an invalid argument This only affects tests, typically manual tests, but when using trace we're debugging and we don't want to crash because of trace itself. No test because a test would cause trace output. Manually verified. Fixes #60649. Change-Id: I97abdb94db05774801ec5da56171f4a1aff35615 Reviewed-on: https://go-review.googlesource.com/c/go/+/501415 TryBot-Result: Gopher Robot Auto-Submit: Robert Griesemer Reviewed-by: Robert Griesemer Reviewed-by: Robert Findley Run-TryBot: Robert Griesemer --- src/cmd/compile/internal/types2/builtins.go | 3 +++ src/go/types/builtins.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go index a65054661e..a3e1981af6 100644 --- a/src/cmd/compile/internal/types2/builtins.go +++ b/src/cmd/compile/internal/types2/builtins.go @@ -893,6 +893,9 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( check.dump("%v: %s", atPos(x1), x1) x1 = &t // use incoming x only for first argument } + if x.mode == invalid { + return + } // trace is only available in test mode - no need to record signature default: diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index fcbb712494..837a9b5e14 100644 --- a/src/go/types/builtins.go +++ b/src/go/types/builtins.go @@ -892,6 +892,9 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b check.dump("%v: %s", x1.Pos(), x1) x1 = &t // use incoming x only for first argument } + if x.mode == invalid { + return + } // trace is only available in test mode - no need to record signature default: -- 2.50.0