Russ Cox | 0b477ef | 2012-02-16 23:48:57 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 2 | |
| 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 Pike | fc0dc04 | 2012-02-19 13:19:43 +1100 | [diff] [blame] | 7 | // Verify that incorrect invocations of the complex predeclared function are detected. |
| 8 | // Does not compile. |
| 9 | |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 10 | package main |
| 11 | |
Rémy Oudompheng | 401e0fe | 2013-03-11 22:55:14 +0100 | [diff] [blame] | 12 | type ( |
| 13 | Float32 float32 |
| 14 | Float64 float64 |
| 15 | Complex64 complex64 |
| 16 | Complex128 complex128 |
| 17 | ) |
| 18 | |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 19 | var ( |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 20 | f32 float32 |
| 21 | f64 float64 |
Rémy Oudompheng | 401e0fe | 2013-03-11 22:55:14 +0100 | [diff] [blame] | 22 | F32 Float32 |
| 23 | F64 Float64 |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 24 | |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 25 | c64 complex64 |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 26 | c128 complex128 |
Rémy Oudompheng | 401e0fe | 2013-03-11 22:55:14 +0100 | [diff] [blame] | 27 | C64 Complex64 |
| 28 | C128 Complex128 |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 29 | ) |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 30 | |
Alberto Donizetti | 1737aef | 2017-04-22 15:28:58 +0200 | [diff] [blame] | 31 | func F1() int { |
| 32 | return 1 |
| 33 | } |
| 34 | |
| 35 | func F3() (int, int, int) { |
| 36 | return 1, 2, 3 |
| 37 | } |
| 38 | |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 39 | func main() { |
| 40 | // ok |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 41 | c64 = complex(f32, f32) |
| 42 | c128 = complex(f64, f64) |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 43 | |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 44 | _ = complex128(0) // ok |
| 45 | _ = complex(f32, f64) // ERROR "complex" |
| 46 | _ = complex(f64, f32) // ERROR "complex" |
Rémy Oudompheng | 401e0fe | 2013-03-11 22:55:14 +0100 | [diff] [blame] | 47 | _ = complex(f32, F32) // ERROR "complex" |
| 48 | _ = complex(F32, f32) // ERROR "complex" |
| 49 | _ = complex(f64, F64) // ERROR "complex" |
| 50 | _ = complex(F64, f64) // ERROR "complex" |
| 51 | |
Alberto Donizetti | 1737aef | 2017-04-22 15:28:58 +0200 | [diff] [blame] | 52 | _ = complex(F1()) // ERROR "expects two arguments.*returns 1" |
| 53 | _ = complex(F3()) // ERROR "expects two arguments.*returns 3" |
| 54 | |
| 55 | _ = complex() // ERROR "missing argument" |
| 56 | |
Rémy Oudompheng | 401e0fe | 2013-03-11 22:55:14 +0100 | [diff] [blame] | 57 | c128 = complex(f32, f32) // ERROR "cannot use" |
| 58 | c64 = complex(f64, f64) // ERROR "cannot use" |
| 59 | |
| 60 | c64 = complex(1.0, 2.0) // ok, constant is untyped |
| 61 | c128 = complex(1.0, 2.0) |
| 62 | C64 = complex(1.0, 2.0) |
| 63 | C128 = complex(1.0, 2.0) |
| 64 | |
| 65 | C64 = complex(f32, f32) // ERROR "cannot use" |
| 66 | C128 = complex(f64, f64) // ERROR "cannot use" |
Alberto Donizetti | 1737aef | 2017-04-22 15:28:58 +0200 | [diff] [blame] | 67 | |
Russ Cox | d97bbab | 2010-04-19 09:21:51 -0700 | [diff] [blame] | 68 | } |