Examples resolved imports based on just the path name,
but this doesn't work for go-name or modules on v2+.
Updates #12794
Fixes #45110
Fixes #56740
Fixes #62059
Change-Id: I8c71b1e5311df04bccbdf319d759d3176a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/728280
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
"go/ast"
"go/token"
"internal/lazyregexp"
- "path"
"slices"
"strconv"
"strings"
// because the package syscall/js is not available in the playground.
return nil
}
- n := path.Base(p)
+ n := assumedPackageName(p)
if s.Name != nil {
n = s.Name.Name
switch n {
--- /dev/null
+package foo_test
+
+import (
+ "example.com/foo/v3"
+ "example.com/go-bar"
+)
+
+func Example() {
+ foo.Print("hello")
+ bar.Print("world")
+ // Output:
+ // hello
+ // world
+}
--- /dev/null
+-- .Play --
+package main
+
+import (
+ "example.com/foo/v3"
+ "example.com/go-bar"
+)
+
+func main() {
+ foo.Print("hello")
+ bar.Print("world")
+}
+-- .Output --
+hello
+world