blob: 2d8a6229d62d59126fc26ad477c50a5e988c5798 [file] [log] [blame]
Russ Cox0b477ef2012-02-16 23:48:57 -05001// errorcheck
Russ Coxd97bbab2010-04-19 09:21:51 -07002
3// Copyright 2010 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
Rob Pikefc0dc042012-02-19 13:19:43 +11007// Verify that incorrect invocations of the complex predeclared function are detected.
8// Does not compile.
9
Russ Coxd97bbab2010-04-19 09:21:51 -070010package main
11
Rémy Oudompheng401e0fe2013-03-11 22:55:14 +010012type (
13 Float32 float32
14 Float64 float64
15 Complex64 complex64
16 Complex128 complex128
17)
18
Russ Coxd97bbab2010-04-19 09:21:51 -070019var (
Russ Coxd97bbab2010-04-19 09:21:51 -070020 f32 float32
21 f64 float64
Rémy Oudompheng401e0fe2013-03-11 22:55:14 +010022 F32 Float32
23 F64 Float64
Russ Coxd97bbab2010-04-19 09:21:51 -070024
Russ Coxf2b5a072011-01-19 23:09:00 -050025 c64 complex64
Russ Coxd97bbab2010-04-19 09:21:51 -070026 c128 complex128
Rémy Oudompheng401e0fe2013-03-11 22:55:14 +010027 C64 Complex64
28 C128 Complex128
Russ Coxd97bbab2010-04-19 09:21:51 -070029)
Russ Coxf2b5a072011-01-19 23:09:00 -050030
Russ Coxd97bbab2010-04-19 09:21:51 -070031func main() {
32 // ok
Russ Coxf2b5a072011-01-19 23:09:00 -050033 c64 = complex(f32, f32)
34 c128 = complex(f64, f64)
Russ Coxd97bbab2010-04-19 09:21:51 -070035
Russ Coxf2b5a072011-01-19 23:09:00 -050036 _ = complex128(0) // ok
37 _ = complex(f32, f64) // ERROR "complex"
38 _ = complex(f64, f32) // ERROR "complex"
Rémy Oudompheng401e0fe2013-03-11 22:55:14 +010039 _ = complex(f32, F32) // ERROR "complex"
40 _ = complex(F32, f32) // ERROR "complex"
41 _ = complex(f64, F64) // ERROR "complex"
42 _ = complex(F64, f64) // ERROR "complex"
43
44 c128 = complex(f32, f32) // ERROR "cannot use"
45 c64 = complex(f64, f64) // ERROR "cannot use"
46
47 c64 = complex(1.0, 2.0) // ok, constant is untyped
48 c128 = complex(1.0, 2.0)
49 C64 = complex(1.0, 2.0)
50 C128 = complex(1.0, 2.0)
51
52 C64 = complex(f32, f32) // ERROR "cannot use"
53 C128 = complex(f64, f64) // ERROR "cannot use"
Russ Coxd97bbab2010-04-19 09:21:51 -070054}