Skip to content

Commit

Permalink
compiler: change 'declared and not used' to 'declared but not used'
Browse files Browse the repository at this point in the history
Go v1.14 has changed this error message, so now that v1.14 is the
minimum Go version supported, change it also in Scriggo.

For #385
  • Loading branch information
gazerro committed Dec 23, 2020
1 parent a4f4412 commit f595639
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion compiler/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (tc *typechecker) exitScope() {
cut = i
}
if len(unused) > 0 {
panic(tc.errorf(unused[len(unused)-1].node, "%s declared and not used", unused[len(unused)-1].ident))
panic(tc.errorf(unused[len(unused)-1].node, "%s declared but not used", unused[len(unused)-1].ident))
}
tc.unusedVars = tc.unusedVars[:cut]
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/checker_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ nodesLoop:
// Append the new nodes removing the function literal.
nodes = append(nodes[:i], append(newNodes, nodes[i+1:]...)...)
tc.scriptFuncDecl = backup
// Avoid error 'declared and not used' by "using" the
// Avoid error 'declared but not used' by "using" the
// identifier.
tc.checkIdentifier(ident, true)
i += 2
Expand Down
4 changes: 2 additions & 2 deletions compiler/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ const noNewVariables = "no new variables on left side of :="
const cannotUseBlankAsValue = "cannot use _ as value"

func declaredNotUsed(v string) string {
return v + " declared and not used"
return v + " declared but not used"
}

func redeclaredInThisBlock(v string) string {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ var checkerStmts = map[string]string{
// `nil.F()`: `use of untyped nil`, // TODO: panics.
`_()`: `cannot use _ as value`,

// Variable declared and not used.
// Variable declared but not used.
`a := 0; { _ = a }`: ok,
`{ { a := 0 } }`: declaredNotUsed("a"),
`{ const A = 0; var B = 0 }`: declaredNotUsed("B"),
Expand Down
2 changes: 1 addition & 1 deletion test/compare/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_errorcheck(t *testing.T) {
src: joinLines([]string{
`package main`,
`func main() {`,
` x := 3 // ERROR "x declared and not used"`,
` x := 3 // ERROR "x declared but not used"`,
`}`,
}),
ext: ".go",
Expand Down
2 changes: 1 addition & 1 deletion test/compare/testdata/errors/bad_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
package main

func main() {
for i := range []int{} { } // ERROR "i declared and not used"
for i := range []int{} { } // ERROR "i declared but not used"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip : 'declared and not used' not reported in type switch https://github.com/open2b/scriggo/issues/474
// skip : 'declared but not used' not reported in type switch https://github.com/open2b/scriggo/issues/474

// errorcheck

Expand All @@ -11,7 +11,7 @@
package main

func f(x interface{}) {
switch t := x.(type) { case int: } // ERROR "declared and not used"
switch t := x.(type) { case int: } // ERROR "declared but not used"
}

func g(x interface{}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip : false positive 'x declared and not used'
// skip : false positive 'x declared but not used'

// errorcheck

Expand Down
4 changes: 2 additions & 2 deletions test/compare/testdata/github.com-golang-go/typeswitch2.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func whatis(x interface{}) string {

func notused(x interface{}) {
// The first t is in a different scope than the 2nd t; it cannot
// be accessed (=> declared and not used error); but it is legal
// be accessed (=> declared but not used error); but it is legal
// to declare it.
switch t := 0; t := x.(type) { // ERROR "declared and not used"
switch t := 0; t := x.(type) { // ERROR "declared but not used"
case int:
_ = t // this is using the t of "t := x.(type)"
}
Expand Down

0 comments on commit f595639

Please sign in to comment.