Generic functions require instantiation, which package plugin doesn't
support, and likely never will. So instead, we can just skip writing
out any generic functions, which avoids an ICE in the plugin
generation code.
This issue doesn't affect GOEXPERIMENT=unified, because it avoids
leaking any non-instantiated types/functions to the rest of the
compiler backend.
Fixes #52937.
Change-Id: Ie35529c5c241e46b77fcb5b8cca48bb99ce7bfcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/406358
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
if s.Pkg.Name != "main" {
continue
}
+ if n.Type().HasTParam() {
+ continue // skip generic functions (#52937)
+ }
ptabs = append(ptabs, n)
}
}
case "build":
// Build Go file.
- _, err := runcmd(goTool(), "build", t.goGcflags(), "-o", "a.exe", long)
+ cmd := []string{goTool(), "build", t.goGcflags()}
+ cmd = append(cmd, flags...)
+ cmd = append(cmd, "-o", "a.exe", long)
+ _, err := runcmd(cmd...)
if err != nil {
t.err = err
}
--- /dev/null
+// build -buildmode=plugin
+
+//go:build !js
+// +build !js
+
+// Copyright 2022 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 main
+
+func main() {}
+func F[T any]() {}
+func G[T any](T) {}