Source file src/internal/types/testdata/fixedbugs/issue51607.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  // Interface types must be ignored during overlap test.
     8  
     9  type (
    10  	T1 interface{int}
    11  	T2 interface{~int}
    12  	T3 interface{T1 | bool | string}
    13  	T4 interface{T2 | ~bool | ~string}
    14  )
    15  
    16  type (
    17  	// overlap errors for non-interface terms
    18  	// (like the interface terms, but explicitly inlined)
    19  	_ interface{int | int /* ERROR "overlapping terms int and int" */ }
    20  	_ interface{int | ~ /* ERROR "overlapping terms ~int and int" */ int}
    21  	_ interface{~int | int /* ERROR "overlapping terms int and ~int" */ }
    22  	_ interface{~int | ~ /* ERROR "overlapping terms ~int and ~int" */ int}
    23  
    24  	_ interface{T1 | bool | string | T1 | bool /* ERROR "overlapping terms bool and bool" */ | string /* ERROR "overlapping terms string and string" */ }
    25  	_ interface{T1 | bool | string | T2 | ~ /* ERROR "overlapping terms ~bool and bool" */ bool | ~ /* ERROR "overlapping terms ~string and string" */ string}
    26  
    27  	// no errors for interface terms
    28  	_ interface{T1 | T1}
    29  	_ interface{T1 | T2}
    30  	_ interface{T2 | T1}
    31  	_ interface{T2 | T2}
    32  
    33  	_ interface{T3 | T3 | int}
    34  	_ interface{T3 | T4 | bool }
    35  	_ interface{T4 | T3 | string }
    36  	_ interface{T4 | T4 | float64 }
    37  )
    38  
    39  func _[_ T1 | bool | string | T1 | bool /* ERROR "overlapping terms" */ ]() {}
    40  func _[_ T1 | bool | string | T2 | ~ /* ERROR "overlapping terms" */ bool ]() {}
    41  func _[_ T2 | ~bool | ~string | T1 | bool /* ERROR "overlapping terms" */ ]() {}
    42  func _[_ T2 | ~bool | ~string | T2 | ~ /* ERROR "overlapping terms" */ bool ]() {}
    43  
    44  func _[_ T3 | T3 | int]() {}
    45  func _[_ T3 | T4 | bool]() {}
    46  func _[_ T4 | T3 | string]() {}
    47  func _[_ T4 | T4 | float64]() {}
    48  
    49  // test cases from issue
    50  
    51  type _ interface {
    52  	interface {bool | int} | interface {bool | string}
    53  }
    54  
    55  type _ interface {
    56  	interface {bool | int} ; interface {bool | string}
    57  }
    58  
    59  type _ interface {
    60  	interface {bool; int} ; interface {bool; string}
    61  }
    62  
    63  type _ interface {
    64  	interface {bool; int} | interface {bool; string}
    65  }

View as plain text