Source file src/internal/types/testdata/fixedbugs/issue51472.go

     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  func _[T comparable](x T) {
     8          _ = x == x
     9  }
    10  
    11  func _[T interface{interface{comparable}}](x T) {
    12          _ = x == x
    13  }
    14  
    15  func _[T interface{comparable; interface{comparable}}](x T) {
    16          _ = x == x
    17  }
    18  
    19  func _[T interface{comparable; ~int}](x T) {
    20          _ = x == x
    21  }
    22  
    23  func _[T interface{comparable; ~[]byte}](x T) {
    24          _ = x /* ERROR "empty type set" */ == x
    25  }
    26  
    27  // TODO(gri) The error message here should be better. See issue #51525.
    28  func _[T interface{comparable; ~int; ~string}](x T) {
    29          _ = x /* ERROR "empty type set" */ == x
    30  }
    31  
    32  // TODO(gri) The error message here should be better. See issue #51525.
    33  func _[T interface{~int; ~string}](x T) {
    34          _ = x /* ERROR "empty type set" */ == x
    35  }
    36  
    37  func _[T interface{comparable; interface{~int}; interface{int|float64}}](x T) {
    38          _ = x == x
    39  }
    40  
    41  func _[T interface{interface{comparable; ~int}; interface{~float64; comparable; m()}}](x T) {
    42          _ = x /* ERROR "empty type set" */ == x
    43  }
    44  
    45  // test case from issue
    46  
    47  func f[T interface{comparable; []byte|string}](x T) {
    48          _ = x == x
    49  }
    50  
    51  func _(s []byte) {
    52  	f /* ERROR "T (type []byte) does not satisfy interface{comparable; []byte | string}" */ (s) // TODO(gri) better error message (T's type set only contains string!)
    53          _ = f[[ /* ERROR "does not satisfy" */ ]byte]
    54  }
    55  

View as plain text