Skip to content

Commit

Permalink
Merge pull request #941 from Daniel-Vetter-Coverwhale/detect-more-con…
Browse files Browse the repository at this point in the history
…flicts

fix: detect conflict when generic is not of the same base type
  • Loading branch information
ernado authored Jan 2, 2024
2 parents 9be9cf9 + c248744 commit ff8a1d3
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions gen/tstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gen

import (
"github.com/go-faster/errors"

"github.com/ogen-go/ogen/gen/ir"
"github.com/ogen-go/ogen/jsonschema"
)
Expand Down Expand Up @@ -120,6 +119,30 @@ func (s *tstorage) saveWType(ref jsonschema.Ref, t *ir.Type) error {
return nil
}

func sameBase(t, tt *ir.Type) bool {
if t.GenericOf != nil {
t = t.GenericOf
}

if tt.GenericOf != nil {
tt = tt.GenericOf
}

if t.Kind == ir.KindAlias && tt.Kind == ir.KindAlias && t.Name == tt.Name {
return true
}

if t.Kind == ir.KindPrimitive && tt.Kind == ir.KindPrimitive && t.Primitive == tt.Primitive {
return true
}

if t.Kind == tt.Kind && t.Schema != nil && tt.Schema != nil && t.Schema.Type == tt.Schema.Type && t.Name == tt.Name {
return true
}

return false
}

func (s *tstorage) merge(other *tstorage) error {
// Check for merge conflicts.
for ref, t := range other.refs {
Expand All @@ -133,7 +156,7 @@ func (s *tstorage) merge(other *tstorage) error {

for name, t := range other.types {
if confT, ok := s.types[name]; ok {
if t.IsGeneric() {
if t.IsGeneric() && sameBase(t, confT) {
for _, feature := range confT.Features {
t.AddFeature(feature)
}
Expand Down

0 comments on commit ff8a1d3

Please sign in to comment.