go/types: incorrect "no such field/method" error in cyclic interface #18395
The following excerpt minimized from a real program causes go/types to emit a spurious error:
The text was updated successfully, but these errors were encountered:
Nice. It appears that the existing algorithm for type-checking interfaces is incorrect, and this subtle example exposes the problem. Type-checking proceeds as follows:
The problem is that the collection of methods for method A depends on B at a time when interface B is not yet finished collecting its methods.
A correct (?) approach may require the collection of all methods first, for all interfaces, before proceeding with type-checking their signatures. This may also eliminate the need for a topological sort of the interfaces before type-checking them (see
This is too invasive a change for Go1.9. Postponing to 1.10.
The comment for phase 2 of checker.interfaceType (typexpr.go:517) requires that embedded interfaces be complete for correctness of the algorithm. Yet, the very next comment (typexpr.go:530) states that underlying embedded interfaces may in fact be incomplete. This is in fact the case and the underlying bug in issue #18395. This change makes sure that new interface types are marked complete when finished (per the implicit definition in Interface.Complete, type.go:302). It also adds a check, enabled in debug mode only, to detect the use of incomplete embedded interfaces during construction of a new interface. In debug mode, this check fails for the testcase in the issue (and several others). This change has no noticeable impact with debug mode disabled. For #18395. Change-Id: Ibb81e47257651282fb3755a80a36ab5d392e636d Reviewed-on: https://go-review.googlesource.com/78955 Reviewed-by: Alan Donovan <email@example.com>
The fix (CL 79575) for #18395 is too risky at this stage of the Go 1.10 release process. Since issue #18395 is easily recognized (but not easily fixed), report an error instead of silently continuing. This avoids inscrutable follow on errors. Also, make sure all empty interfaces are "completed", and adjust printing code to report incomplete interfaces. For #18395. Change-Id: I7fa5f97ff31ac9775c9a6d318fce9f526b0350cd Reviewed-on: https://go-review.googlesource.com/80455 Reviewed-by: Alan Donovan <firstname.lastname@example.org>
R=go1.11 types.Eval historically never evaluated any delayed tests, which included verification of validity of map keys, but also function literal bodies. Now, embedded interfaces are also type-checked in a delayed fashion, so it becomes imperative to do all delayed checks for eval (otherwise obviously incorrect type expressions are silently accepted). Enabling the delayed tests also removes the restriction that function literals were not type-checked. Also fixed a bug where eval wouldn't return a type-checking error because check.handleBailout was using the wrong err variable. Added tests that verify that method set computation is using the right types when evaluating interfaces with embedded types. For #18395. For #22992. Change-Id: I574fa84568b5158bca4b4ccd4ef5abb616fbf896 Reviewed-on: https://go-review.googlesource.com/84898 Reviewed-by: Alan Donovan <email@example.com>
Now that #18395 is fixed, let's see if we can insist on vet during go test being able to type-check packages again. Change-Id: Iaa55a4d9c582ba743df2347d28c24f130e16e406 Reviewed-on: https://go-review.googlesource.com/108555 Run-TryBot: Russ Cox <firstname.lastname@example.org> Reviewed-by: Robert Griesemer <email@example.com>