Text file src/go/types/testdata/fixedbugs/issue43110.src

     1  // Copyright 2020 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 P *struct{}
     8  
     9  func _() {
    10  	// want an error even if the switch is empty
    11  	var a struct{ _ func() }
    12  	switch a /* ERROR cannot switch on a */ {
    13  	}
    14  
    15  	switch a /* ERROR cannot switch on a */ {
    16  	case a: // no follow-on error here
    17  	}
    18  
    19  	// this is ok because f can be compared to nil
    20  	var f func()
    21  	switch f {
    22  	}
    23  
    24  	switch f {
    25  	case nil:
    26  	}
    27  
    28  	switch (func())(nil) {
    29  	case nil:
    30  	}
    31  
    32  	switch (func())(nil) {
    33  	case f /* ERROR invalid case f in switch on .* \(func can only be compared to nil\) */ :
    34  	}
    35  
    36  	switch nil /* ERROR use of untyped nil in switch expression */ {
    37  	}
    38  
    39  	// this is ok
    40  	switch P(nil) {
    41  	case P(nil):
    42  	}
    43  }
    44  

View as plain text