Text file src/go/types/testdata/fixedbugs/issue51658.go2

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package p
     6  
     7  type F { // ERROR expected type
     8  	float64
     9  } // ERROR expected declaration
    10  
    11  func _[T F | int](x T) {
    12  	_ = x == 0 // don't crash when recording type of 0
    13  }
    14  
    15  // test case from issue
    16  
    17  type FloatType { // ERROR expected type
    18  	float32 | float64
    19  } // ERROR expected declaration
    20  
    21  type IntegerType interface {
    22  	int8 | int16 | int32 | int64 | int |
    23  		uint8 | uint16 | uint32 | uint64 | uint
    24  }
    25  
    26  type ComplexType interface {
    27  	complex64 | complex128
    28  }
    29  
    30  type Number interface {
    31  	FloatType | IntegerType | ComplexType
    32  }
    33  
    34  func GetDefaultNumber[T Number](value, defaultValue T) T {
    35  	if value == 0 {
    36  		return defaultValue
    37  	}
    38  	return value
    39  }
    40  

View as plain text