Skip to content

Commit

Permalink
Fix bug with type inference when shortcut return type syntax is used.
Browse files Browse the repository at this point in the history
Fixes #469.
  • Loading branch information
nsf committed Sep 3, 2017
1 parent 67bdaab commit c7fddb3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions _testing/DESC
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ test.0056 - type alias method propagation
test.0057 - embedded interfaces
test.0058 - canonical import aliases
test.0059 - canonical import aliases, more complicated case (doesn't work as you might expect)
test.0060 - shortcut syntax for return value types in functions
Empty file added _testing/test.0060/cursor.109
Empty file.
2 changes: 2 additions & 0 deletions _testing/test.0060/out.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Found 1 candidates:
func Read(p []byte) (n int, err error)
10 changes: 10 additions & 0 deletions _testing/test.0060/test.go.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import "io"

func f() (a, b io.Reader, c error) { return a }

func main() {
a, b, c := f()
b.
}
15 changes: 6 additions & 9 deletions decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,14 @@ func func_return_type(f *ast.FuncType, index int) ast.Expr {
i := 0
var field *ast.Field
for _, field = range f.Results.List {
if i >= index {
return field.Type
}
n := 1
if field.Names != nil {
i += len(field.Names)
} else {
i++
n = len(field.Names)
}
}
if i >= index {
return field.Type
if i <= index && index < i+n {
return field.Type
}
i += n
}
return nil
}
Expand Down

0 comments on commit c7fddb3

Please sign in to comment.