1
0
mirror of https://github.com/golang/go synced 2024-11-17 14:04:48 -07:00

go/types, types2: always return an underlying type from optype

Optype should never return a defined type.

Change-Id: I37b29e0c958e127e75e834e71d6392ea80827773
Reviewed-on: https://go-review.googlesource.com/c/go/+/357694
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Robert Findley 2021-10-21 13:23:29 -04:00
parent 392bb0677c
commit 8151b56c5d
4 changed files with 18 additions and 2 deletions

View File

@ -304,3 +304,11 @@ func _[P interface{ ~[]E }, E interface{ map[string]P } ]() P {
return P{E{"foo": x}}
return P{{"foo": x}, {}}
}
// This is a degenerate case with a singleton type set, but we can create
// composite literals even if the structural type is a defined type.
type MyInts []int
func _[P MyInts]() P {
return P{}
}

View File

@ -57,7 +57,7 @@ func optype(typ Type) Type {
// See also issue #39680.
if u := t.structuralType(); u != nil {
assert(u != typ) // "naked" type parameters cannot be embedded
return u
return under(u) // optype should always return an underlying type
}
return theTop
}

View File

@ -310,3 +310,11 @@ func _[P interface{ ~[]E }, E interface{ map[string]P } ]() P {
return P{E{"foo": x}}
return P{{"foo": x}, {}}
}
// This is a degenerate case with a singleton type set, but we can create
// composite literals even if the structural type is a defined type.
type MyInts []int
func _[P MyInts]() P {
return P{}
}

View File

@ -57,7 +57,7 @@ func optype(typ Type) Type {
// See also issue #39680.
if u := t.structuralType(); u != nil {
assert(u != typ) // "naked" type parameters cannot be embedded
return u
return under(u) // optype should always return an underlying type
}
return theTop
}