Debian Codegraph @

_test/composite15.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5 )
6
7 func interfaceAsInts() {
8 var a interface{}
9 b := 2
10 c := 3
11 a = []int{b, c}
12
13 d, ok := a.([]int)
14 if !ok {
15 println("nope")
16 return
17 }
18
19 for _, v := range d {
20 fmt.Println(v)
21 }
22 }
23
24 func interfaceAsInterfaces() {
25 var a, b, c interface{}
26 b = 2
27 c = 3
28 a = []interface{}{b, c}
29
30 d, ok := a.([]interface{})
31 if !ok {
32 println("nope")
33 return
34 }
35 fmt.Println(d)
36
37 for _, v := range d {
38 fmt.Println(v)
39 }
40 }
41
42 func main() {
43 interfaceAsInts()
44 interfaceAsInterfaces()
45 }
46
47 // Output:
48 // 2
49 // 3
50 // [2 3]
51 // 2
52 // 3