fix bug where package name suffix increased with every use

master
Felix Lange 8 years ago
parent c180464f1d
commit 1fd1f70537
  1. 1
      internal/tests/nameclash/input.go
  2. 12
      internal/tests/nameclash/output.go
  3. 2
      typeutil.go

@ -24,6 +24,7 @@ type dec struct{}
type Y struct { type Y struct {
Foo json.Foo `optional:"true"` Foo json.Foo `optional:"true"`
Foo2 json.Foo `optional:"true"`
Bar errors.Foo `optional:"true"` Bar errors.Foo `optional:"true"`
Gazonk YJSON `optional:"true"` Gazonk YJSON `optional:"true"`
Over int `optional:"true"` Over int `optional:"true"`

@ -12,12 +12,14 @@ import (
func (y *Y) MarshalJSON() ([]byte, error) { func (y *Y) MarshalJSON() ([]byte, error) {
type YJSON0 struct { type YJSON0 struct {
Foo *json0.Foo `optional:"true"` Foo *json0.Foo `optional:"true"`
Foo2 *json0.Foo `optional:"true"`
Bar *errors0.Foo `optional:"true"` Bar *errors0.Foo `optional:"true"`
Gazonk *YJSON `optional:"true"` Gazonk *YJSON `optional:"true"`
Over *enc `optional:"true"` Over *enc `optional:"true"`
} }
var enc0 YJSON0 var enc0 YJSON0
enc0.Foo = &y.Foo enc0.Foo = &y.Foo
enc0.Foo2 = &y.Foo2
enc0.Bar = &y.Bar enc0.Bar = &y.Bar
enc0.Gazonk = &y.Gazonk enc0.Gazonk = &y.Gazonk
enc0.Over = (*enc)(&y.Over) enc0.Over = (*enc)(&y.Over)
@ -27,6 +29,7 @@ func (y *Y) MarshalJSON() ([]byte, error) {
func (y *Y) UnmarshalJSON(input []byte) error { func (y *Y) UnmarshalJSON(input []byte) error {
type YJSON0 struct { type YJSON0 struct {
Foo *json0.Foo `optional:"true"` Foo *json0.Foo `optional:"true"`
Foo2 *json0.Foo `optional:"true"`
Bar *errors0.Foo `optional:"true"` Bar *errors0.Foo `optional:"true"`
Gazonk *YJSON `optional:"true"` Gazonk *YJSON `optional:"true"`
Over *enc `optional:"true"` Over *enc `optional:"true"`
@ -39,6 +42,9 @@ func (y *Y) UnmarshalJSON(input []byte) error {
if dec.Foo != nil { if dec.Foo != nil {
x.Foo = *dec.Foo x.Foo = *dec.Foo
} }
if dec.Foo2 != nil {
x.Foo2 = *dec.Foo2
}
if dec.Bar != nil { if dec.Bar != nil {
x.Bar = *dec.Bar x.Bar = *dec.Bar
} }
@ -55,12 +61,14 @@ func (y *Y) UnmarshalJSON(input []byte) error {
func (y *Y) MarshalYAML() (interface{}, error) { func (y *Y) MarshalYAML() (interface{}, error) {
type YYAML struct { type YYAML struct {
Foo *json0.Foo `optional:"true"` Foo *json0.Foo `optional:"true"`
Foo2 *json0.Foo `optional:"true"`
Bar *errors0.Foo `optional:"true"` Bar *errors0.Foo `optional:"true"`
Gazonk *YJSON `optional:"true"` Gazonk *YJSON `optional:"true"`
Over *enc `optional:"true"` Over *enc `optional:"true"`
} }
var enc0 YYAML var enc0 YYAML
enc0.Foo = &y.Foo enc0.Foo = &y.Foo
enc0.Foo2 = &y.Foo2
enc0.Bar = &y.Bar enc0.Bar = &y.Bar
enc0.Gazonk = &y.Gazonk enc0.Gazonk = &y.Gazonk
enc0.Over = (*enc)(&y.Over) enc0.Over = (*enc)(&y.Over)
@ -70,6 +78,7 @@ func (y *Y) MarshalYAML() (interface{}, error) {
func (y *Y) UnmarshalYAML(unmarshal func(interface{}) error) error { func (y *Y) UnmarshalYAML(unmarshal func(interface{}) error) error {
type YYAML struct { type YYAML struct {
Foo *json0.Foo `optional:"true"` Foo *json0.Foo `optional:"true"`
Foo2 *json0.Foo `optional:"true"`
Bar *errors0.Foo `optional:"true"` Bar *errors0.Foo `optional:"true"`
Gazonk *YJSON `optional:"true"` Gazonk *YJSON `optional:"true"`
Over *enc `optional:"true"` Over *enc `optional:"true"`
@ -82,6 +91,9 @@ func (y *Y) UnmarshalYAML(unmarshal func(interface{}) error) error {
if dec.Foo != nil { if dec.Foo != nil {
x.Foo = *dec.Foo x.Foo = *dec.Foo
} }
if dec.Foo2 != nil {
x.Foo2 = *dec.Foo2
}
if dec.Bar != nil { if dec.Bar != nil {
x.Bar = *dec.Bar x.Bar = *dec.Bar
} }

@ -166,7 +166,7 @@ func (s *fileScope) addReferences(typ types.Type) {
// rebuild the import name cache. // rebuild the import name cache.
func (s *fileScope) insertImport(pkg *types.Package) { func (s *fileScope) insertImport(pkg *types.Package) {
i := sort.Search(len(s.imports), func(i int) bool { i := sort.Search(len(s.imports), func(i int) bool {
return s.imports[i].Path() > pkg.Path() return s.imports[i].Path() >= pkg.Path()
}) })
if i < len(s.imports) && s.imports[i] == pkg { if i < len(s.imports) && s.imports[i] == pkg {
return return

Loading…
Cancel
Save