aboutsummaryrefslogtreecommitdiff
path: root/gopls/internal/lsp/analysis/unusedvariable/testdata/src/assign/a.go
blob: aa9f46e5b31e98f235cc85cf128115b31b3ad8ae (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
// Copyright 2022 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.

package a

import (
	"fmt"
	"os"
)

type A struct {
	b int
}

func singleAssignment() {
	v := "s" // want `v declared (and|but) not used`

	s := []int{ // want `s declared (and|but) not used`
		1,
		2,
	}

	a := func(s string) bool { // want `a declared (and|but) not used`
		return false
	}

	if 1 == 1 {
		s := "v" // want `s declared (and|but) not used`
	}

	panic("I should survive")
}

func noOtherStmtsInBlock() {
	v := "s" // want `v declared (and|but) not used`
}

func partOfMultiAssignment() {
	f, err := os.Open("file") // want `f declared (and|but) not used`
	panic(err)
}

func sideEffects(cBool chan bool, cInt chan int) {
	b := <-c            // want `b declared (and|but) not used`
	s := fmt.Sprint("") // want `s declared (and|but) not used`
	a := A{             // want `a declared (and|but) not used`
		b: func() int {
			return 1
		}(),
	}
	c := A{<-cInt}          // want `c declared (and|but) not used`
	d := fInt() + <-cInt    // want `d declared (and|but) not used`
	e := fBool() && <-cBool // want `e declared (and|but) not used`
	f := map[int]int{       // want `f declared (and|but) not used`
		fInt(): <-cInt,
	}
	g := []int{<-cInt}       // want `g declared (and|but) not used`
	h := func(s string) {}   // want `h declared (and|but) not used`
	i := func(s string) {}() // want `i declared (and|but) not used`
}

func commentAbove() {
	// v is a variable
	v := "s" // want `v declared (and|but) not used`
}

func fBool() bool {
	return true
}

func fInt() int {
	return 1
}