File: issue-1381.go

package info (click to toggle)
golang-github-traefik-yaegi 0.16.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 24,608 kB
  • sloc: sh: 457; makefile: 39
file content (58 lines) | stat: -rw-r--r-- 1,281 bytes parent folder | download | duplicates (2)
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
package main

import (
	"bytes"
	"fmt"
)

func main() {
	var bufPtrOne *bytes.Buffer
	var bufPtrTwo *bytes.Buffer
	var bufPtrThree *bytes.Buffer
	var bufPtrFour *bytes.Buffer

	for i := 0; i < 2; i++ {
		bufOne := bytes.Buffer{}
		bufTwo := &bytes.Buffer{}
		var bufThree bytes.Buffer
		bufFour := new(bytes.Buffer)

		if bufPtrOne == nil {
			bufPtrOne = &bufOne
		} else if bufPtrOne == &bufOne {
			fmt.Println("bufOne was not properly redeclared")
		} else {
			fmt.Println("bufOne is properly redeclared")
		}

		if bufPtrTwo == nil {
			bufPtrTwo = bufTwo
		} else if bufPtrTwo == bufTwo {
			fmt.Println("bufTwo was not properly redeclared")
		} else {
			fmt.Println("bufTwo is properly redeclared")
		}

		if bufPtrThree == nil {
			bufPtrThree = &bufThree
		} else if bufPtrThree == &bufThree {
			fmt.Println("bufThree was not properly redeclared")
		} else {
			fmt.Println("bufThree is properly redeclared")
		}

		if bufPtrFour == nil {
			bufPtrFour = bufFour
		} else if bufPtrFour == bufFour {
			fmt.Println("bufFour was not properly redeclared")
		} else {
			fmt.Println("bufFour is properly redeclared")
		}
	}
}

// Output:
// bufOne is properly redeclared
// bufTwo is properly redeclared
// bufThree is properly redeclared
// bufFour is properly redeclared