return
}
var names []string
+ names = append(names, pkg.GoFiles...)
names = append(names, pkg.CgoFiles...)
names = append(names, pkg.TestGoFiles...) // These are also in the "foo" package.
prefixDirectory(directory, names)
pkg.values[x] = val
}
}
+ // By providing the Context with our own error function, it will continue
+ // past the first error. There is no need for that function to do anything.
context := types.Context{
- Expr: exprFn,
+ Expr: exprFn,
+ Error: func(error) {},
}
// Type check the package.
_, err := context.Check(fs, astFiles)
return
}
}
- if f.pkg == nil { // Nothing more to do.
- return
- }
// Verb is good. If nargs>1, we have something like %.*s and all but the final
// arg must be integer.
for i := 0; i < nargs-1; i++ {
// If we have a call to a method called Error that satisfies the Error interface,
// then it's ok. Otherwise it's something like (*T).Error from the testing package
// and we need to check it.
- if name == "Error" && f.pkg != nil && f.isErrorMethodCall(call) {
+ if name == "Error" && f.isErrorMethodCall(call) {
return
}
// If it's an Error call now, it's probably for printing errors.
if !isLn {
// Check the signature to be sure: there are niladic functions called "error".
- if f.pkg == nil || firstArg != 0 || f.numArgsInSignature(call) != firstArg {
+ if firstArg != 0 || f.numArgsInSignature(call) != firstArg {
f.Badf(call.Pos(), "no args in %s call", name)
}
}
}
// numArgsInSignature tells how many formal arguments the function type
-// being called has. Assumes type checking is on (f.pkg != nil).
+// being called has.
func (f *File) numArgsInSignature(call *ast.CallExpr) int {
// Check the type of the function or method declaration
typ := f.pkg.types[call.Fun]
// isErrorMethodCall reports whether the call is of a method with signature
// func Error() string
-// where "string" is the universe's string type. We know the method is called "Error"
-// and f.pkg is set.
+// where "string" is the universe's string type. We know the method is called "Error".
func (f *File) isErrorMethodCall(call *ast.CallExpr) bool {
// Is it a selector expression? Otherwise it's a function call, not a method call.
sel, ok := call.Fun.(*ast.SelectorExpr)
return
}
- // Check that the CompositeLit's type is a slice or array (which need no tag), if possible.
- if f.pkg != nil {
- typ := f.pkg.types[c]
- if typ != nil {
- // If it's a named type, pull out the underlying type.
- if namedType, ok := typ.(*types.NamedType); ok {
- typ = namedType.Underlying
- }
- switch typ.(type) {
- case *types.Slice:
- return
- case *types.Array:
- return
- }
+ // Check that the CompositeLit's type is a slice or array (which needs no tag), if possible.
+ typ := f.pkg.types[c]
+ if typ != nil {
+ // If it's a named type, pull out the underlying type.
+ if namedType, ok := typ.(*types.NamedType); ok {
+ typ = namedType.Underlying
+ }
+ switch typ.(type) {
+ case *types.Slice:
+ return
+ case *types.Array:
+ return
}
}
f.Warnf(c.Pos(), "unresolvable package for %s.%s literal", pkg.Name, s.Sel.Name)
return
}
- typ := path + "." + s.Sel.Name
- if *compositeWhiteList && untaggedLiteralWhitelist[typ] {
+ typeName := path + "." + s.Sel.Name
+ if *compositeWhiteList && untaggedLiteralWhitelist[typeName] {
return
}