-
Notifications
You must be signed in to change notification settings - Fork 18k
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
cmd/compile: able to use interface with type constraints #51578
Comments
The declaration type TypeSet interface{ int | string } is ok, but one shouldn't be able to use this type in the conversion of |
Also, compiling with
|
Simpler reproducer: var _ = (*interface{int})(nil) should not be permitted. |
Change https://go.dev/cl/391275 mentions this issue: |
Change https://go.dev/cl/391357 mentions this issue: |
…e type constraints Pointer types may appear in expressions *P and we don't know if we have an indirection (P is a pointer value) or a pointer type (P is a type) until we type-check P. Don't forget to check that a type P must be an ordinary (not a constraint) type in this special case. Fixes #51578. Change-Id: If782cc6dd2a602a498574c78c99e40c3b72274a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/391275 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> (cherry picked from commit 3a5e3d8) Reviewed-on: https://go-review.googlesource.com/c/go/+/391357 Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
I'm a little behind on the latest with generics, but my understanding is that interfaces with type sets can currently only be used as type constraints.
If so, I would expect the following to not compile:
However, not only does it compile, it also executes with incorrect results:
The
v.Set(reflect.ValueOf([]byte("hello")))
is expected to panic since the underlying interface is specified to only holdint
orstring
.\cc @mdempsky @griesemer @ianlancetaylor
The text was updated successfully, but these errors were encountered: