Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
switch3.go73 linesDownload Raw Back to test
1// errorcheck2 3// Copyright 2011 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7// Verify that erroneous switch statements are detected by the compiler.8// Does not compile.9 10package main11 12type I interface {13	M()14}15 16func bad() {17	var i I18	var s string19 20	switch i {21	case s: // ERROR "mismatched types string and I|incompatible types"22	}23 24	switch s {25	case i: // ERROR "mismatched types I and string|incompatible types"26	}27 28	var m, m1 map[int]int29	switch m {30	case nil:31	case m1: // ERROR "can only compare map m to nil|map can only be compared to nil|cannot compare"32	default:33	}34 35	var a, a1 []int36	switch a {37	case nil:38	case a1: // ERROR "can only compare slice a to nil|slice can only be compared to nil|cannot compare"39	default:40	}41 42	var f, f1 func()43	switch f {44	case nil:45	case f1: // ERROR "can only compare func f to nil|func can only be compared to nil|cannot compare"46	default:47	}48 49	var ar, ar1 [4]func()50	switch ar { // ERROR "cannot switch on"51	case ar1:52	default:53	}54 55	var st, st1 struct{ f func() }56	switch st { // ERROR "cannot switch on"57	case st1:58	}59}60 61func good() {62	var i interface{}63	var s string64 65	switch i {66	case s:67	}68 69	switch s {70	case i:71	}72}73 
codekingpro/portable-devtools · Team Ai