Commit 3cbf672a authored by Eric Myhre's avatar Eric Myhre

Fix semantic bug in TypeUnion: lookup key is not always the member type's name!

While fixing this it occurs to me that we could in theory also support
more than one name alias that will be mapped onto the same concrete type.
...
But Let's Not with that.  It would increase the code complexity and more
importantly, *it would be lossy to do so*.  So let's not open that can
of worms: straying into lossiness territory is far worse than whatever
other hypothetical problems one might imagine trying to solve.
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent 6cd06a38
...@@ -99,10 +99,17 @@ func (t TypeList) ValueIsNullable() bool { ...@@ -99,10 +99,17 @@ func (t TypeList) ValueIsNullable() bool {
} }
// UnionMembers returns a set of all the types that can inhabit this Union. // UnionMembers returns a set of all the types that can inhabit this Union.
func (t TypeUnion) UnionMembers() map[TypeName]Type { func (t TypeUnion) UnionMembers() map[Type]struct{} {
m := make(map[TypeName]Type, len(t.values)) m := make(map[Type]struct{}, len(t.values)+len(t.valuesKinded))
for k, v := range t.values { switch t.style {
m[k] = v case UnionStyle_Kinded:
for _, v := range t.valuesKinded {
m[v] = struct{}{}
}
default:
for _, v := range t.values {
m[v] = struct{}{}
}
} }
return m return m
} }
......
...@@ -125,7 +125,7 @@ type TypeUnion struct { ...@@ -125,7 +125,7 @@ type TypeUnion struct {
anyType anyType
style UnionStyle style UnionStyle
valuesKinded map[ipld.ReprKind]Type // for Style==Kinded valuesKinded map[ipld.ReprKind]Type // for Style==Kinded
values map[TypeName]Type // for Style!=Kinded (always defined, just not used in Kinded lookups) values map[string]Type // for Style!=Kinded (note, key is freetext, not necessarily TypeName of the value)
typeHintKey string // for Style==Envelope|Inline typeHintKey string // for Style==Envelope|Inline
contentKey string // for Style==Envelope contentKey string // for Style==Envelope
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment