Fix to follow some recent changes to the go/types API.
diff --git a/lint.go b/lint.go
index 1a8c8d4..eff0bbd 100644
--- a/lint.go
+++ b/lint.go
@@ -944,7 +944,6 @@
}
lhsTyp := f.pkg.typeOf(v.Type)
rhsTyp := f.pkg.typeOf(rhs)
- scope := f.pkg.scopeOf(v.Names[0])
if lhsTyp != nil && rhsTyp != nil && !types.Identical(lhsTyp, rhsTyp) {
// Assignment to a different type is not redundant.
return false
@@ -961,7 +960,7 @@
return false
}
// If the RHS is an untyped const, only warn if the LHS type is its default type.
- if defType, ok := f.isUntypedConst(rhs, scope); ok && !isIdent(v.Type, defType) {
+ if defType, ok := f.isUntypedConst(rhs); ok && !isIdent(v.Type, defType) {
return false
}
// If the LHS is a known weaker type, and we couldn't type check both sides,
@@ -1472,15 +1471,11 @@
// isUntypedConst reports whether expr is an untyped constant,
// and indicates what its default type is.
// scope may be nil.
-func (f *file) isUntypedConst(expr ast.Expr, scope *types.Scope) (defType string, ok bool) {
- typ := f.pkg.typeOf(expr)
- if typ == nil || scope == nil {
- return "", false
- }
-
+func (f *file) isUntypedConst(expr ast.Expr) (defType string, ok bool) {
// Re-evaluate expr outside of its context to see if it's untyped.
// (An expr evaluated within, for example, an assignment context will get the type of the LHS.)
- tv, err := types.EvalNode(f.fset, expr, f.pkg.typesPkg, scope)
+ exprStr := f.render(expr)
+ tv, err := types.Eval(f.fset, f.pkg.typesPkg, expr.Pos(), exprStr)
if err != nil {
return "", false
}
diff --git a/lint_test.go b/lint_test.go
index 91a981e..e6b25de 100644
--- a/lint_test.go
+++ b/lint_test.go
@@ -271,9 +271,7 @@
if err != nil {
t.Fatalf("Type checking %q: %v", src, err)
}
- // Use the first child scope of the package, which will be the file scope.
- scope := pkg.Scope().Child(0)
- tv, err := types.Eval(test.typString, pkg, scope)
+ tv, err := types.Eval(fset, pkg, token.NoPos, test.typString)
if err != nil {
t.Errorf("types.Eval(%q): %v", test.typString, err)
continue