-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/types: incorrect "no such field/method" error in cyclic interface #18395
Comments
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. |
Change https://golang.org/cl/78955 mentions this issue: |
Status update: Started working on this. Have a basic solution based on proposed solution above (collecting methods first, before creating the respective types). Working on cleaning up the approach (it's a lot of code). |
If it's a lot of code maybe this should wait for Go 1.11? |
@rsc: Maybe. The issue is that not having this will prevent vet from working in some cases. They are rare but so far three have been filed. I want to work on this just a tad longer to see what the final outcome is. |
Change https://golang.org/cl/79575 mentions this issue: |
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 protected]>
Decided to postpone submit of fix to 1.11 in discussion with @rsc, @ianlancetaylor . See also related #22890. |
Change https://golang.org/cl/80455 mentions this issue: |
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 <[email protected]>
Change https://golang.org/cl/84898 mentions this issue: |
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 protected]>
Change https://golang.org/cl/108555 mentions this issue: |
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 <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
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: