mirror of https://github.com/golang/go.git
gopls/internal/regtest: fix regtest failures from "undefined" errors
Following-up on CL 434636, also update gopls regtests to handle the new "undefined: ..." errors replacing "undeclared name: ..." errors in go/types. Change-Id: I53a05623b63851e8165ab3685aff2cdf494fa5b6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/434639 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
1bfc4699d4
commit
eb45e986a7
|
|
@ -261,6 +261,12 @@ func importDiagnostics(fix *imports.ImportFix, diagnostics []protocol.Diagnostic
|
|||
if ident == fix.IdentName {
|
||||
results = append(results, diagnostic)
|
||||
}
|
||||
// "undefined: X" may be an unresolved import at Go 1.20+.
|
||||
case strings.HasPrefix(diagnostic.Message, "undefined: "):
|
||||
ident := strings.TrimPrefix(diagnostic.Message, "undefined: ")
|
||||
if ident == fix.IdentName {
|
||||
results = append(results, diagnostic)
|
||||
}
|
||||
// "could not import: X" may be an invalid import.
|
||||
case strings.HasPrefix(diagnostic.Message, "could not import: "):
|
||||
ident := strings.TrimPrefix(diagnostic.Message, "could not import: ")
|
||||
|
|
|
|||
|
|
@ -618,7 +618,7 @@ func main() {
|
|||
env.RegexpReplace("x/x.go", `package x`, `package main`)
|
||||
env.Await(OnceMet(
|
||||
env.DoneWithChange(),
|
||||
env.DiagnosticAtRegexpWithMessage("x/main.go", `fmt`, "undeclared name")))
|
||||
env.DiagnosticAtRegexp("x/main.go", `fmt`)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1800,7 +1800,7 @@ var Bar = Foo
|
|||
|
||||
Run(t, files, func(t *testing.T, env *Env) {
|
||||
env.OpenFile("foo.go")
|
||||
env.Await(env.DiagnosticAtRegexpWithMessage("bar.go", `Foo`, "undeclared name"))
|
||||
env.Await(env.DiagnosticAtRegexp("bar.go", `Foo`))
|
||||
env.RegexpReplace("foo.go", `\+build`, "")
|
||||
env.Await(EmptyDiagnostics("bar.go"))
|
||||
})
|
||||
|
|
@ -1831,15 +1831,15 @@ package main
|
|||
env.OpenFile("main.go")
|
||||
env.OpenFile("other.go")
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexpWithMessage("main.go", "asdf", "undeclared name"),
|
||||
env.DiagnosticAtRegexpWithMessage("main.go", "fdas", "undeclared name"),
|
||||
env.DiagnosticAtRegexp("main.go", "asdf"),
|
||||
env.DiagnosticAtRegexp("main.go", "fdas"),
|
||||
)
|
||||
env.SetBufferContent("other.go", "package main\n\nasdf")
|
||||
// The new diagnostic in other.go should not suppress diagnostics in main.go.
|
||||
env.Await(
|
||||
OnceMet(
|
||||
env.DiagnosticAtRegexpWithMessage("other.go", "asdf", "expected declaration"),
|
||||
env.DiagnosticAtRegexpWithMessage("main.go", "asdf", "undeclared name"),
|
||||
env.DiagnosticAtRegexp("main.go", "asdf"),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
|
@ -2082,7 +2082,7 @@ func F[T C](_ T) {
|
|||
var d protocol.PublishDiagnosticsParams
|
||||
env.Await(
|
||||
OnceMet(
|
||||
env.DiagnosticAtRegexpWithMessage("main.go", `C`, "undeclared name"),
|
||||
env.DiagnosticAtRegexp("main.go", `C`),
|
||||
ReadDiagnostics("main.go", &d),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1157,8 +1157,8 @@ func (Server) Foo() {}
|
|||
// as invalid. So we need to wait for the metadata of main_test.go to be
|
||||
// updated before moving other_test.go back to the main_test package.
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexpWithMessage("other_test.go", "Server", "undeclared"),
|
||||
env.DiagnosticAtRegexpWithMessage("main_test.go", "otherConst", "undeclared"),
|
||||
env.DiagnosticAtRegexp("other_test.go", "Server"),
|
||||
env.DiagnosticAtRegexp("main_test.go", "otherConst"),
|
||||
)
|
||||
env.RegexpReplace("other_test.go", "main", "main_test")
|
||||
env.Await(
|
||||
|
|
|
|||
Loading…
Reference in New Issue