File tree 5 files changed +175
-1
lines changed
5 files changed +175
-1
lines changed Original file line number Diff line number Diff line change @@ -391,7 +391,13 @@ func (r *reader) readFunc(fun *ast.FuncDecl) {
391
391
// exactly one (named or anonymous) result associated
392
392
// with the first type in result signature (there may
393
393
// be more than one result)
394
- if n , imp := baseTypeName (res .Type ); ! imp && r .isVisible (n ) {
394
+ factoryType := res .Type
395
+ if t , ok := factoryType .(* ast.ArrayType ); ok && t .Len == nil {
396
+ // We consider functions that return slices of type T (or
397
+ // pointers to T) as factory functions of T.
398
+ factoryType = t .Elt
399
+ }
400
+ if n , imp := baseTypeName (factoryType ); ! imp && r .isVisible (n ) {
395
401
if typ := r .lookupType (n ); typ != nil {
396
402
// associate function with typ
397
403
typ .funcs .set (fun )
Original file line number Diff line number Diff line change
1
+ //
2
+ PACKAGE issue18063
3
+
4
+ IMPORTPATH
5
+ testdata/issue18063
6
+
7
+ FILENAMES
8
+ testdata/issue18063.go
9
+
10
+ FUNCTIONS
11
+ // NewArray is not a factory function because arrays of type T are ...
12
+ func NewArray() [1]T
13
+
14
+ // NewPointerArray is not a factory function because arrays of ...
15
+ func NewPointerArray() [1]*T
16
+
17
+ // NewPointerSliceOfSlice is not a factory function because slices ...
18
+ func NewPointerSliceOfSlice() [][]*T
19
+
20
+ // NewSlice3 is not a factory function because 3 nested slices of ...
21
+ func NewSlice3() [][][]T
22
+
23
+ // NewSliceOfSlice is not a factory function because slices of a ...
24
+ func NewSliceOfSlice() [][]T
25
+
26
+
27
+ TYPES
28
+ //
29
+ type T struct{}
30
+
31
+ //
32
+ func New() T
33
+
34
+ //
35
+ func NewPointer() *T
36
+
37
+ //
38
+ func NewPointerOfPointer() **T
39
+
40
+ //
41
+ func NewPointerSlice() []*T
42
+
43
+ //
44
+ func NewSlice() []T
45
+
Original file line number Diff line number Diff line change
1
+ //
2
+ PACKAGE issue18063
3
+
4
+ IMPORTPATH
5
+ testdata/issue18063
6
+
7
+ FILENAMES
8
+ testdata/issue18063.go
9
+
10
+ FUNCTIONS
11
+ // NewArray is not a factory function because arrays of type T are ...
12
+ func NewArray() [1]T
13
+
14
+ // NewPointerArray is not a factory function because arrays of ...
15
+ func NewPointerArray() [1]*T
16
+
17
+ // NewPointerSliceOfSlice is not a factory function because slices ...
18
+ func NewPointerSliceOfSlice() [][]*T
19
+
20
+ // NewSlice3 is not a factory function because 3 nested slices of ...
21
+ func NewSlice3() [][][]T
22
+
23
+ // NewSliceOfSlice is not a factory function because slices of a ...
24
+ func NewSliceOfSlice() [][]T
25
+
26
+
27
+ TYPES
28
+ //
29
+ type T struct{}
30
+
31
+ //
32
+ func New() T
33
+
34
+ //
35
+ func NewPointer() *T
36
+
37
+ //
38
+ func NewPointerOfPointer() **T
39
+
40
+ //
41
+ func NewPointerSlice() []*T
42
+
43
+ //
44
+ func NewSlice() []T
45
+
Original file line number Diff line number Diff line change
1
+ //
2
+ PACKAGE issue18063
3
+
4
+ IMPORTPATH
5
+ testdata/issue18063
6
+
7
+ FILENAMES
8
+ testdata/issue18063.go
9
+
10
+ FUNCTIONS
11
+ // NewArray is not a factory function because arrays of type T are ...
12
+ func NewArray() [1]T
13
+
14
+ // NewPointerArray is not a factory function because arrays of ...
15
+ func NewPointerArray() [1]*T
16
+
17
+ // NewPointerSliceOfSlice is not a factory function because slices ...
18
+ func NewPointerSliceOfSlice() [][]*T
19
+
20
+ // NewSlice3 is not a factory function because 3 nested slices of ...
21
+ func NewSlice3() [][][]T
22
+
23
+ // NewSliceOfSlice is not a factory function because slices of a ...
24
+ func NewSliceOfSlice() [][]T
25
+
26
+
27
+ TYPES
28
+ //
29
+ type T struct{}
30
+
31
+ //
32
+ func New() T
33
+
34
+ //
35
+ func NewPointer() *T
36
+
37
+ //
38
+ func NewPointerOfPointer() **T
39
+
40
+ //
41
+ func NewPointerSlice() []*T
42
+
43
+ //
44
+ func NewSlice() []T
45
+
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package issue18063
6
+
7
+ type T struct {}
8
+
9
+ func New () T { return T {} }
10
+ func NewPointer () * T { return & T {} }
11
+ func NewPointerSlice () []* T { return []* T {& T {}} }
12
+ func NewSlice () []T { return []T {T {}} }
13
+ func NewPointerOfPointer () * * T { x := & T {}; return & x }
14
+
15
+ // NewArray is not a factory function because arrays of type T are not
16
+ // factory functions of type T.
17
+ func NewArray () [1 ]T { return [1 ]T {T {}} }
18
+
19
+ // NewPointerArray is not a factory function because arrays of type *T are not
20
+ // factory functions of type T.
21
+ func NewPointerArray () [1 ]* T { return [1 ]* T {& T {}} }
22
+
23
+ // NewSliceOfSlice is not a factory function because slices of a slice of
24
+ // type *T are not factory functions of type T.
25
+ func NewSliceOfSlice () [][]T { return []T {[]T {}} }
26
+
27
+ // NewPointerSliceOfSlice is not a factory function because slices of a
28
+ // slice of type *T are not factory functions of type T.
29
+ func NewPointerSliceOfSlice () [][]* T { return []* T {[]* T {}} }
30
+
31
+ // NewSlice3 is not a factory function because 3 nested slices of type T
32
+ // are not factory functions of type T.
33
+ func NewSlice3 () [][][]T { return []T {[]T {[]T {}}} }
You can’t perform that action at this time.
0 commit comments