summaryrefslogtreecommitdiff
path: root/test/fixedbugs/issue5162.go
blob: b14eae7863dc1b8437ca5a3ea6fa10c1a94de452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// runoutput

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// issue 5162: bad array equality when multiple comparisons
// happen in the same expression.

package main

import (
	"fmt"
	"strings"
)

const template = `
func CheckEqNNN_TTT() {
	onesA := [NNN]ttt{ONES}
	onesB := [NNN]ttt{ONES}
	twos := [NNN]ttt{TWOS}
	if onesA != onesB {
		println("onesA != onesB in CheckEqNNN_TTT")
	}
	if onesA == twos {
		println("onesA == twos in CheckEqNNN_TTT")
	}
	if onesB == twos {
		println("onesB == twos in CheckEqNNN_TTT")
	}
	if s := fmt.Sprint(onesA == onesB, onesA != twos, onesB != twos); s != "true true true" {
		println("fail in CheckEqNNN_TTT:", s)
	}
}

func CheckEqNNN_TTTExtraVar() {
	onesA := [NNN]ttt{ONES}
	onesB := [NNN]ttt{ONES}
	twos := [NNN]ttt{TWOS}
	onesX := onesA
	if onesA != onesB {
		println("onesA != onesB in CheckEqNNN_TTTExtraVar")
	}
	if onesA == twos {
		println("onesA == twos in CheckEqNNN_TTTExtraVar")
	}
	if onesB == twos {
		println("onesB == twos in CheckEqNNN_TTTExtraVar")
	}
	if s := fmt.Sprint(onesA == onesB, onesA != twos, onesB != twos); s != "true true true" {
		println("fail in CheckEqNNN_TTTExtraVar:", s)
	}
	if s := fmt.Sprint(onesB == onesX); s != "true" {
		println("extra var fail in CheckEqNNN_TTTExtraVar")
	}
}
`

func main() {
	fmt.Print("// run\n\n")
	fmt.Print("// THIS FILE IS AUTO-GENERATED\n\n")
	fmt.Print("package main\n\n")
	fmt.Println(`import "fmt"`)

	types := []string{
		"int", "int8", "int16", "int32", "int64",
		"uint", "uint8", "uint16", "uint32", "uint64",
		"float32", "float64"}
	tocall := make([]string, 0, 32*len(types))
	for i := 1; i <= 32; i++ {
		for _, typ := range types {
			src := template
			src = strings.Replace(src, "NNN", fmt.Sprint(i), -1)
			src = strings.Replace(src, "TTT", strings.Title(typ), -1)
			src = strings.Replace(src, "ttt", typ, -1)
			src = strings.Replace(src, "ONES", "1"+strings.Repeat(", 1", i-1), -1)
			src = strings.Replace(src, "TWOS", "2"+strings.Repeat(", 2", i-1), -1)
			fmt.Print(src)
			tocall = append(tocall, fmt.Sprintf("CheckEq%d_%s", i, strings.Title(typ)))
		}
	}
	fmt.Println("func main() {")
	for _, fun := range tocall {
		fmt.Printf("\t%s()\n", fun)
		fmt.Printf("\t%sExtraVar()\n", fun)
	}
	fmt.Println("}")
}