mirror of https://github.com/golang/go.git
go/types, types2: use correct underlying type in union set computation
Fixes #51658. Change-Id: Ibf415d7e12849b8f50b58d74713613d4e65bc347 Reviewed-on: https://go-review.googlesource.com/c/go/+/392575 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
8419ec295c
commit
41fe746857
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type F { // ERROR syntax error
|
||||
float64
|
||||
} // ERROR syntax error
|
||||
|
||||
func _[T F | int](x T) {
|
||||
_ = x == 0 // don't crash when recording type of 0
|
||||
}
|
||||
|
||||
// test case from issue
|
||||
|
||||
type FloatType { // ERROR syntax error
|
||||
float32 | float64
|
||||
} // ERROR syntax error
|
||||
|
||||
type IntegerType interface {
|
||||
int8 | int16 | int32 | int64 | int |
|
||||
uint8 | uint16 | uint32 | uint64 | uint
|
||||
}
|
||||
|
||||
type ComplexType interface {
|
||||
complex64 | complex128
|
||||
}
|
||||
|
||||
type Number interface {
|
||||
FloatType | IntegerType | ComplexType
|
||||
}
|
||||
|
||||
func GetDefaultNumber[T Number](value, defaultValue T) T {
|
||||
if value == 0 {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
|
@ -406,7 +406,7 @@ func computeUnionTypeSet(check *Checker, unionSets map[*Union]*_TypeSet, pos syn
|
|||
// For now we don't permit type parameters as constraints.
|
||||
assert(!isTypeParam(t.typ))
|
||||
terms = computeInterfaceTypeSet(check, pos, ui).terms
|
||||
} else if t.typ == Typ[Invalid] {
|
||||
} else if u == Typ[Invalid] {
|
||||
continue
|
||||
} else {
|
||||
if t.tilde && !Identical(t.typ, u) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type F { // ERROR expected type
|
||||
float64
|
||||
} // ERROR expected declaration
|
||||
|
||||
func _[T F | int](x T) {
|
||||
_ = x == 0 // don't crash when recording type of 0
|
||||
}
|
||||
|
||||
// test case from issue
|
||||
|
||||
type FloatType { // ERROR expected type
|
||||
float32 | float64
|
||||
} // ERROR expected declaration
|
||||
|
||||
type IntegerType interface {
|
||||
int8 | int16 | int32 | int64 | int |
|
||||
uint8 | uint16 | uint32 | uint64 | uint
|
||||
}
|
||||
|
||||
type ComplexType interface {
|
||||
complex64 | complex128
|
||||
}
|
||||
|
||||
type Number interface {
|
||||
FloatType | IntegerType | ComplexType
|
||||
}
|
||||
|
||||
func GetDefaultNumber[T Number](value, defaultValue T) T {
|
||||
if value == 0 {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
|
@ -406,7 +406,7 @@ func computeUnionTypeSet(check *Checker, unionSets map[*Union]*_TypeSet, pos tok
|
|||
// For now we don't permit type parameters as constraints.
|
||||
assert(!isTypeParam(t.typ))
|
||||
terms = computeInterfaceTypeSet(check, pos, ui).terms
|
||||
} else if t.typ == Typ[Invalid] {
|
||||
} else if u == Typ[Invalid] {
|
||||
continue
|
||||
} else {
|
||||
if t.tilde && !Identical(t.typ, u) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue