gopls/internal/regtest/codelens: avoid compiler bug

Because of how the compiler internally represents variable references,
it sometimes gets position information incorrectly for them. The
codelens test hits this issue because for

	var x string
	fmt.Println(x)

the diagnostic about "x" escaping to heap (which actually refers to
the implicit conversion to "interface{}" type) should be rightly
reported at the "x" identifier within the call arguments list.
However, due to the aforementioned compiler bug, historically we
reported the diagnostic at the "(" token instead.

In -G=3 mode, the compiler (correctly) report the diagnostic at "x"
instead; but with GOEXPERIMENT=unified, the compiler intentionally
matches the original -G=0 behavior and continues reporting at "("
instead.

This CL avoids the issue entirely by changing the line to
"fmt.Println(42)", which avoids the issue because the compiler always
correctly prints the diagnostic then at "42".

Change-Id: I22d4c756ae801489f3f16c440e4339bc9b115fb0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/343875
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/gopls/internal/regtest/codelens/codelens_test.go b/gopls/internal/regtest/codelens/codelens_test.go
index d89b8e0..ad35a29 100644
--- a/gopls/internal/regtest/codelens/codelens_test.go
+++ b/gopls/internal/regtest/codelens/codelens_test.go
@@ -303,8 +303,7 @@
 import "fmt"
 
 func main() {
-	var x string
-	fmt.Println(x)
+	fmt.Println(42)
 }
 `
 	WithOptions(
@@ -320,7 +319,7 @@
 		d := &protocol.PublishDiagnosticsParams{}
 		env.Await(
 			OnceMet(
-				DiagnosticAt("main.go", 6, 12),
+				DiagnosticAt("main.go", 5, 13),
 				ReadDiagnostics("main.go", d),
 			),
 		)
@@ -330,12 +329,12 @@
 			if d.Severity != protocol.SeverityInformation {
 				t.Fatalf("unexpected diagnostic severity %v, wanted Information", d.Severity)
 			}
-			if strings.Contains(d.Message, "x escapes") {
+			if strings.Contains(d.Message, "42 escapes") {
 				found = true
 			}
 		}
 		if !found {
-			t.Fatalf(`expected to find diagnostic with message "escape(x escapes to heap)", found none`)
+			t.Fatalf(`expected to find diagnostic with message "escape(42 escapes to heap)", found none`)
 		}
 
 		// Editing a buffer should cause gc_details diagnostics to disappear, since
@@ -346,7 +345,7 @@
 		// Saving a buffer should re-format back to the original state, and
 		// re-enable the gc_details diagnostics.
 		env.SaveBuffer("main.go")
-		env.Await(DiagnosticAt("main.go", 6, 12))
+		env.Await(DiagnosticAt("main.go", 5, 13))
 
 		// Toggle the GC details code lens again so now it should be off.
 		env.ExecuteCodeLensCommand("main.go", command.GCDetails)