@@ -151,10 +151,11 @@ type reader struct {
151
151
notes map [string ][]* Note
152
152
153
153
// declarations
154
- imports map [string ]int
155
- values []* Value // consts and vars
156
- types map [string ]* namedType
157
- funcs methodSet
154
+ imports map [string ]int
155
+ hasDotImp bool // if set, package contains a dot import
156
+ values []* Value // consts and vars
157
+ types map [string ]* namedType
158
+ funcs methodSet
158
159
159
160
// support for package-local error type declarations
160
161
errorDecl bool // if set, type "error" was declared locally
@@ -471,6 +472,9 @@ func (r *reader) readFile(src *ast.File) {
471
472
if s , ok := spec .(* ast.ImportSpec ); ok {
472
473
if import_ , err := strconv .Unquote (s .Path .Value ); err == nil {
473
474
r .imports [import_ ] = 1
475
+ if s .Name != nil && s .Name .Name == "." {
476
+ r .hasDotImp = true
477
+ }
474
478
}
475
479
}
476
480
}
@@ -641,11 +645,12 @@ func (r *reader) computeMethodSets() {
641
645
func (r * reader ) cleanupTypes () {
642
646
for _ , t := range r .types {
643
647
visible := r .isVisible (t .name )
644
- if t .decl == nil && (predeclaredTypes [t .name ] || t .isEmbedded && visible ) {
648
+ if t .decl == nil && (predeclaredTypes [t .name ] || visible && ( t .isEmbedded || r . hasDotImp ) ) {
645
649
// t.name is a predeclared type (and was not redeclared in this package),
646
650
// or it was embedded somewhere but its declaration is missing (because
647
- // the AST is incomplete): move any associated values, funcs, and methods
648
- // back to the top-level so that they are not lost.
651
+ // the AST is incomplete), or we have a dot-import (and all bets are off):
652
+ // move any associated values, funcs, and methods back to the top-level so
653
+ // that they are not lost.
649
654
// 1) move values
650
655
r .values = append (r .values , t .values ... )
651
656
// 2) move factory functions
0 commit comments