Commit 80e9a7f0 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: have all or no parameter named in exported signatures

Binary export format only.

Make sure we don't accidentally export an unnamed parameter
in signatures which expect all named parameters; otherwise
we crash during import. Appears to happen for _ (blank)
parameter names, as observed in method signatures such as
the one at: x/tools/godoc/analysis/analysis.go:76.

Fixes #15470.

TBR=mdempsky

Change-Id: I1b1184bf08c4c09d8a46946539c4b8c341acdb84
Reviewed-on: https://go-review.googlesource.com/22543Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent e8d4ffb7
...@@ -819,19 +819,30 @@ func (p *exporter) param(q *Field, n int, numbered bool) { ...@@ -819,19 +819,30 @@ func (p *exporter) param(q *Field, n int, numbered bool) {
} }
p.typ(t) p.typ(t)
if n > 0 { if n > 0 {
p.string(parName(q, numbered)) if name := parName(q, numbered); name != "" {
// Because of (re-)exported inlined functions p.string(name)
// the importpkg may not be the package to which this // Because of (re-)exported inlined functions
// function (and thus its parameter) belongs. We need to // the importpkg may not be the package to which this
// supply the parameter package here. We need the package // function (and thus its parameter) belongs. We need to
// when the function is inlined so we can properly resolve // supply the parameter package here. We need the package
// the name. // when the function is inlined so we can properly resolve
// TODO(gri) This is compiler-specific. Try using importpkg // the name.
// here and then update the symbols if we find an inlined // TODO(gri) This is compiler-specific. Try using importpkg
// body only. Otherwise, the parameter name is ignored and // here and then update the symbols if we find an inlined
// the package doesn't matter. This would remove an int // body only. Otherwise, the parameter name is ignored and
// (likely 1 byte) for each named parameter. // the package doesn't matter. This would remove an int
p.pkg(q.Sym.Pkg) // (likely 1 byte) for each named parameter.
p.pkg(q.Sym.Pkg)
} else {
// Sometimes we see an empty name even for n > 0.
// This appears to happen for interface methods
// with _ (blank) parameter names. Make sure we
// have a proper name and package so we don't crash
// during import (see also issue #15470).
// TODO(gri) review parameter encoding
p.string("_")
p.pkg(localpkg)
}
} }
// TODO(gri) This is compiler-specific (escape info). // TODO(gri) This is compiler-specific (escape info).
// Move into compiler-specific section eventually? // Move into compiler-specific section eventually?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment