1// errorcheck 2 3// Copyright 2009 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7// Verify that erroneous initialization expressions are caught by the compiler 8// Does not compile. 9 10package main 11 12type S struct { 13 A, B, C, X, Y, Z int 14} 15 16type T struct { 17 S 18} 19 20var x = 1 21var a1 = S{0, X: 1} // ERROR "mixture|undefined" "too few values" 22var a2 = S{Y: 3, Z: 2, Y: 3} // ERROR "duplicate" 23var a3 = T{S{}, 2, 3, 4, 5, 6} // ERROR "convert|too many" 24var a4 = [5]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} // ERROR "index|too many" 25var a5 = []byte{x: 2} // ERROR "index" 26var a6 = []byte{1: 1, 2: 2, 1: 3} // ERROR "duplicate" 27 28var ok1 = S{} // should be ok 29var ok2 = T{S: ok1} // should be ok 30 31// These keys can be computed at compile time but they are 32// not constants as defined by the spec, so they do not trigger 33// compile-time errors about duplicate key values. 34// See issue 4555. 35 36type Key struct{ X, Y int } 37 38var _ = map[Key]string{ 39 Key{1, 2}: "hello", 40 Key{1, 2}: "world", 41} 42