From c16e2224683082f4b90cf9f17f27590ead0cfe99 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 23 Jan 2024 10:31:53 -0500 Subject: [PATCH] gopls/internal/test/integration: add regtest for hover crash This CL adds a test that confirms the bug reported in golang/go#60592 is fixed at master; the test fails at commit 87ad891. Fixes golang/go#60592 Change-Id: Id9436d019a782a385228f77ce92988005711e700 Reviewed-on: https://go-review.googlesource.com/c/tools/+/557715 Reviewed-by: Robert Findley LUCI-TryBot-Result: Go LUCI Auto-Submit: Alan Donovan --- .../test/integration/misc/hover_test.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gopls/internal/test/integration/misc/hover_test.go b/gopls/internal/test/integration/misc/hover_test.go index d246814e9d9..66bce0d768c 100644 --- a/gopls/internal/test/integration/misc/hover_test.go +++ b/gopls/internal/test/integration/misc/hover_test.go @@ -491,3 +491,26 @@ func TestHoverEmbedDirective(t *testing.T) { } }) } + +func TestHoverBrokenImport_Issue60592(t *testing.T) { + const files = ` +-- go.mod -- +module testdata +go 1.18 + +-- p.go -- +package main + +import foo "a" + +func _() { + foo.Print() +} + +` + Run(t, files, func(t *testing.T, env *Env) { + env.OpenFile("p.go") + // This request should not crash gopls. + _, _, _ = env.Editor.Hover(env.Ctx, env.RegexpSearch("p.go", "foo[.]")) + }) +}