Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(896)

Delta Between Two Patch Sets: cmd/vet/types.go

Issue 12811043: code review 12811043: cmd/vet: flag redundant invocations of String and Error... (Closed)
Left Patch Set: diff -r 93e7f796eeab https://code.google.com/p/go.tools Created 10 years, 7 months ago
Right Patch Set: diff -r 400755f06d55 https://code.google.com/p/go.tools Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/vet/testdata/print.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // This file contains the pieces of the tool that use typechecking from the go/t ypes package. 5 // This file contains the pieces of the tool that use typechecking from the go/t ypes package.
6 6
7 package main 7 package main
8 8
9 import ( 9 import (
10 "go/ast" 10 "go/ast"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 266 }
267 // There must be a receiver for it to be a method call. Otherwise it is 267 // There must be a receiver for it to be a method call. Otherwise it is
268 // a function, not something that satisfies the error interface. 268 // a function, not something that satisfies the error interface.
269 if sig.Recv == nil { 269 if sig.Recv == nil {
270 return false 270 return false
271 } 271 }
272 // There must be no arguments. Already verified by type checking, but be thorough. 272 // There must be no arguments. Already verified by type checking, but be thorough.
273 if sig.Params().Len() > 0 { 273 if sig.Params().Len() > 0 {
274 return false 274 return false
275 } 275 }
276 » // Finally the real questions. 276 » // Finally the real question.
277 » // There must be one result. 277 » return hasStringReturn(sig)
278 » if sig.Results().Len() != 1 { 278 }
279 » » return false 279
280 » } 280 // returnsString reports whether expr is a call of a function that returns a str ing.
281 » // It must have return type "string" from the universe. 281 // If it cannot be type checked it returns true.
282 » return sig.Results().At(0).Type() == types.Typ[types.String] 282 func (f *File) returnsString(expr ast.Expr) bool {
283 } 283 » typ := f.pkg.types[expr]
284 » if typ == nil {
285 » » return true
286 » }
287 » sig, ok := typ.(*types.Signature)
288 » if !ok {
289 » » return false
290 » }
291 » return hasStringReturn(sig)
292 }
293
294 // hasStringReturn reports whether the function signature has exactly
295 // one return value, of universe type string.
296 func hasStringReturn(sig *types.Signature) bool {
297 » return sig.Results().Len() == 1 && sig.Results().At(0).Type() == types.T yp[types.String]
298 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b