Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue11945.go

raw
1 // run
2
3 // Copyright 2017 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 package main
8
9 import "fmt"
10
11 // issue 17446
12 const (
13 _ = real(0) // from bug report
14 _ = imag(0) // from bug report
15
16 // if the arguments are untyped, the results must be untyped
17 // (and compatible with types that can represent the values)
18 _ int = real(1)
19 _ int = real('a')
20 _ int = real(2.0)
21 _ int = real(3i)
22
23 _ float32 = real(1)
24 _ float32 = real('a')
25 _ float32 = real(2.1)
26 _ float32 = real(3.2i)
27
28 _ float64 = real(1)
29 _ float64 = real('a')
30 _ float64 = real(2.1)
31 _ float64 = real(3.2i)
32
33 _ int = imag(1)
34 _ int = imag('a')
35 _ int = imag(2.1 + 3i)
36 _ int = imag(3i)
37
38 _ float32 = imag(1)
39 _ float32 = imag('a')
40 _ float32 = imag(2.1 + 3.1i)
41 _ float32 = imag(3i)
42
43 _ float64 = imag(1)
44 _ float64 = imag('a')
45 _ float64 = imag(2.1 + 3.1i)
46 _ float64 = imag(3i)
47 )
48
49 var tests = []struct {
50 code string
51 got, want interface{}
52 }{
53 {"real(1)", real(1), 1.0},
54 {"real('a')", real('a'), float64('a')},
55 {"real(2.0)", real(2.0), 2.0},
56 {"real(3.2i)", real(3.2i), 0.0},
57
58 {"imag(1)", imag(1), 0.0},
59 {"imag('a')", imag('a'), 0.0},
60 {"imag(2.1 + 3.1i)", imag(2.1 + 3.1i), 3.1},
61 {"imag(3i)", imag(3i), 3.0},
62 }
63
64 func main() {
65 // verify compile-time evaluated constant expressions
66 for _, test := range tests {
67 if test.got != test.want {
68 panic(fmt.Sprintf("%s: %v (%T) != %v (%T)", test.code, test.got, test.got, test.want, test.want))
69 }
70 }
71 }