Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dev.go2go] go/types: use actual (not underlying) types of type list …
…elements for interface satisfaction This is a rule change in an attempt to streamline interface satisfaction: If a (constraint) interface contains a type list, a type argument's type or underlying type must be included in the type list (and the interface's methods must be present, of course). Until now, a type argument's under- lying type had to be one of the underlying types of the types in the type list. The effect is subtle: Because an underlying type is never a defined type, if a type list contains defined types, only those defined types satisfy the interface. If we want the interface to be more flexible, we can in- clude non-defined types in its type list. In the common case, type lists simply contain predeclared types (whose underlying types are themselves), so this doesn't matter. An observable difference appears only for code that currently uses defined types in constraint type lists: such code becomes slightly more restrictive. The primary benefit of this change is that it opens the door for general (non-constraint) use of interfaces with type lists: Using the same rules as for constraint satisfaction, a value may be assigned to a variable of such an interface if it or its underlying type of the value is included int the interface's type list. If the type list contains only defined types, the respective interface acts like a sum type: it can only contain values of those types (and nil). This CL only changes the rules for constraints. It does not permit interfaces with type lists for general (non-constraint) use for now. Change-Id: I3f25b9d883dd865a74c583efee4be2e22258d493 Reviewed-on: https://go-review.googlesource.com/c/go/+/248265 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
- Loading branch information