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"
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"
26
27var ok1 = S { }	// should be ok
28var ok2 = T { S: ok1 }	// should be ok
29
30// These keys can be computed at compile time but they are
31// not constants as defined by the spec, so they do not trigger
32// compile-time errors about duplicate key values.
33// See issue 4555.
34
35type Key struct {X, Y int}
36
37var _ = map[Key]string{
38	Key{1,2}: "hello",
39	Key{1,2}: "world",
40}
41