1// compile 2 3// Copyright 2020 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// Make sure that literal value can be passed to struct 8// blank field of array/struct type, see issue #38690. 9 10package main 11 12type A1 = [0]int 13type A2 = [1]int 14 15type S1 struct{} 16 17type S2 struct { 18 x int 19} 20 21type S3 = struct{} 22 23type S4 = struct{ x int } 24 25type S struct { 26 x int 27 _ [0]int 28 _ [1]int 29 _ A1 30 _ A2 31 _ S1 32 _ S2 33 _ S3 34 _ S4 35 _ [1]S4 36} 37 38var s = S{1, [0]int{}, [1]int{1}, A1{}, A2{1}, S1{}, S2{1}, S3{}, S4{1}, [1]S4{}} 39 40func main() { 41 f1() 42 mustPanic(f2) 43 mustPanic(f3) 44} 45 46func f1() { 47 _ = S{1, [0]int{}, [1]int{1}, A1{}, A2{1}, S1{}, S2{1}, S3{}, S4{1}, [1]S4{}} 48} 49 50func f2() { 51 _ = S{1, [0]int{}, [1]int{1}, A1{}, A2{1}, S1{}, S2{1}, S3{}, func() S4 { panic("") }(), [1]S4{}} 52} 53 54func f3() { 55 _ = S{1, [0]int{}, [1]int{1}, A1{}, A2{1}, S1{}, S2{1}, S3{}, S4{1}, func() [1]S4 { panic("") }()} 56} 57 58func mustPanic(f func()) { 59 defer func() { 60 if recover() == nil { 61 panic("expected panic, got nil") 62 } 63 }() 64 f() 65} 66