Home | History | Annotate | Download | only in fixedbugs
      1 // errorcheck
      2 
      3 // Copyright 2016 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 func foo() (int, int) {
     10 	return 2.3 // ERROR "not enough arguments to return\n\thave \(number\)\n\twant \(int, int\)"
     11 }
     12 
     13 func foo2() {
     14 	return int(2), 2 // ERROR "too many arguments to return\n\thave \(int, number\)\n\twant \(\)"
     15 }
     16 
     17 func foo3(v int) (a, b, c, d int) {
     18 	if v >= 0 {
     19 		return 1 // ERROR "not enough arguments to return\n\thave \(number\)\n\twant \(int, int, int, int\)"
     20 	}
     21 	return 2, 3 // ERROR "not enough arguments to return\n\thave \(number, number\)\n\twant \(int, int, int, int\)"
     22 }
     23 
     24 func foo4(name string) (string, int) {
     25 	switch name {
     26 	case "cow":
     27 		return "moo" // ERROR "not enough arguments to return\n\thave \(string\)\n\twant \(string, int\)"
     28 	case "dog":
     29 		return "dog", 10, true // ERROR "too many arguments to return\n\thave \(string, number, bool\)\n\twant \(string, int\)"
     30 	case "fish":
     31 		return "" // ERROR "not enough arguments to return\n\thave \(string\)\n\twant \(string, int\)"
     32 	default:
     33 		return "lizard", 10
     34 	}
     35 }
     36 
     37 type S int
     38 type T string
     39 type U float64
     40 
     41 func foo5() (S, T, U) {
     42 	if false {
     43 		return "" // ERROR "not enough arguments to return\n\thave \(string\)\n\twant \(S, T, U\)"
     44 	} else {
     45 		ptr := new(T)
     46 		return ptr // ERROR "not enough arguments to return\n\thave \(\*T\)\n\twant \(S, T, U\)"
     47 	}
     48 	return new(S), 12.34, 1 + 0i, 'r', true // ERROR "too many arguments to return\n\thave \(\*S, number, number, number, bool\)\n\twant \(S, T, U\)"
     49 }
     50 
     51 func foo6() (T, string) {
     52 	return "T", true, true // ERROR "too many arguments to return\n\thave \(string, bool, bool\)\n\twant \(T, string\)"
     53 }
     54