From 916e861fd969e19e918e5b24c45a834c63dd8ee4 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 18 Mar 2019 12:19:26 -0700 Subject: [PATCH] cmd/compile: fix importing rewritten f(g()) calls golang.org/cl/166983 started serializing the Ninit field of OCALL nodes within function inline bodies (necessary to fix a regression in building crypto/ecdsa with -gcflags=-l=4), but this means the Ninit field needs to be typechecked when the imported function body is used. It's unclear why this wasn't necessary for the crypto/ecdsa regression. Fixes #30907. Change-Id: Id5f0bf3c4d17bbd6d5318913b859093c93a0a20c Reviewed-on: https://go-review.googlesource.com/c/go/+/168199 Run-TryBot: Matthew Dempsky Reviewed-by: Robert Griesemer TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/typecheck.go | 1 + test/fixedbugs/issue30907.dir/a.go | 19 +++++++++++++++++++ test/fixedbugs/issue30907.dir/b.go | 11 +++++++++++ test/fixedbugs/issue30907.go | 7 +++++++ 4 files changed, 38 insertions(+) create mode 100644 test/fixedbugs/issue30907.dir/a.go create mode 100644 test/fixedbugs/issue30907.dir/b.go create mode 100644 test/fixedbugs/issue30907.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 2468f52b74..a746b34180 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -1239,6 +1239,7 @@ func typecheck1(n *Node, top int) (res *Node) { // call and call like case OCALL: + typecheckslice(n.Ninit.Slice(), ctxStmt) // imported rewritten f(g()) calls (#30907) n.Left = typecheck(n.Left, ctxExpr|Etype|ctxCallee) if n.Left.Diag() { n.SetDiag(true) diff --git a/test/fixedbugs/issue30907.dir/a.go b/test/fixedbugs/issue30907.dir/a.go new file mode 100644 index 0000000000..e1a5c0cc3b --- /dev/null +++ b/test/fixedbugs/issue30907.dir/a.go @@ -0,0 +1,19 @@ +// Copyright 2019 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 a + +type UUID string + +func New() UUID { + return Must(NewRandom()) +} + +func NewRandom() (UUID, error) { + return "", nil +} + +func Must(uuid UUID, err error) UUID { + return uuid +} diff --git a/test/fixedbugs/issue30907.dir/b.go b/test/fixedbugs/issue30907.dir/b.go new file mode 100644 index 0000000000..f4f5fc4fdd --- /dev/null +++ b/test/fixedbugs/issue30907.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2019 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 + +import "./a" + +func F() { + a.New() +} diff --git a/test/fixedbugs/issue30907.go b/test/fixedbugs/issue30907.go new file mode 100644 index 0000000000..973ae1dcef --- /dev/null +++ b/test/fixedbugs/issue30907.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2019 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 ignored -- 2.48.1