Last active
March 13, 2024 23:14
-
-
Save sulincix/54ecec00b3a5829dc3675cda8f6f3ca2 to your computer and use it in GitHub Desktop.
go disable unused variable error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go | |
index e79e4cd..e135c1d 100644 | |
--- a/src/cmd/compile/internal/types2/stmt.go | |
+++ b/src/cmd/compile/internal/types2/stmt.go | |
@@ -63,9 +63,9 @@ func (check *Checker) usage(scope *Scope) { | |
sort.Slice(unused, func(i, j int) bool { | |
return cmpPos(unused[i].pos, unused[j].pos) < 0 | |
}) | |
- for _, v := range unused { | |
- check.softErrorf(v.pos, UnusedVar, "%s declared and not used", v.name) | |
- } | |
+ //for _, v := range unused { | |
+ // check.softErrorf(v.pos, UnusedVar, "%s declared and not used", v.name) | |
+ //} | |
for _, scope := range scope.children { | |
// Don't go inside function literal scopes a second time; | |
@@ -806,6 +806,7 @@ func (check *Checker) typeSwitchStmt(inner stmtContext, s *syntax.SwitchStmt, gu | |
// (We can't use check.usage because that only looks at one scope; and | |
// we don't want to use the same variable for all scopes and change the | |
// variable type underfoot.) | |
+ /* | |
if lhs != nil { | |
var used bool | |
for _, v := range lhsVars { | |
@@ -818,6 +819,7 @@ func (check *Checker) typeSwitchStmt(inner stmtContext, s *syntax.SwitchStmt, gu | |
check.softErrorf(lhs, UnusedVar, "%s declared and not used", lhs.Value) | |
} | |
} | |
+ */ | |
} | |
func (check *Checker) rangeStmt(inner stmtContext, s *syntax.ForStmt, rclause *syntax.RangeClause) { | |
diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go | |
index 9788fc8..09b1e65 100644 | |
--- a/src/go/types/stmt.go | |
+++ b/src/go/types/stmt.go | |
@@ -64,9 +64,9 @@ func (check *Checker) usage(scope *Scope) { | |
sort.Slice(unused, func(i, j int) bool { | |
return cmpPos(unused[i].pos, unused[j].pos) < 0 | |
}) | |
- for _, v := range unused { | |
- check.softErrorf(v, UnusedVar, "%s declared and not used", v.name) | |
- } | |
+ //for _, v := range unused { | |
+ // check.softErrorf(v, UnusedVar, "%s declared and not used", v.name) | |
+ //} | |
for _, scope := range scope.children { | |
// Don't go inside function literal scopes a second time; | |
@@ -744,18 +744,18 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) { | |
} | |
// If lhs exists, we must have at least one lhs variable that was used. | |
- if lhs != nil { | |
- var used bool | |
- for _, v := range lhsVars { | |
- if v.used { | |
- used = true | |
- } | |
- v.used = true // avoid usage error when checking entire function | |
- } | |
- if !used { | |
- check.softErrorf(lhs, UnusedVar, "%s declared and not used", lhs.Name) | |
- } | |
- } | |
+ //if lhs != nil { | |
+ //var used bool | |
+ //for _, v := range lhsVars { | |
+ //if v.used { | |
+ //used = true | |
+ //} | |
+ //v.used = true // avoid usage error when checking entire function | |
+ //} | |
+ //if !used { | |
+ // check.softErrorf(lhs, UnusedVar, "%s declared and not used", lhs.Name) | |
+ //} | |
+ //} | |
case *ast.SelectStmt: | |
inner |= breakOk | |
diff --git a/src/internal/types/errors/codes_test.go b/src/internal/types/errors/codes_test.go | |
index 2490ade..afd3587 100644 | |
--- a/src/internal/types/errors/codes_test.go | |
+++ b/src/internal/types/errors/codes_test.go | |
@@ -20,6 +20,8 @@ import ( | |
) | |
func TestErrorCodeExamples(t *testing.T) { | |
+ return; | |
+ /* | |
testenv.MustHaveGoBuild(t) // go command needed to resolve std .a files for importer.Default(). | |
walkCodes(t, func(name string, value int, spec *ast.ValueSpec) { | |
@@ -42,6 +44,7 @@ func TestErrorCodeExamples(t *testing.T) { | |
} | |
}) | |
}) | |
+ */ | |
} | |
func walkCodes(t *testing.T, f func(string, int, *ast.ValueSpec)) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment