Skip to content

Commit da55dc0

Browse files
fix: to_sorbet_type should not return branded types
1 parent af0543e commit da55dc0

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

lib/lithic/internal/type/enum.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ def coerce(value, state:)
112112
#
113113
# @return [Object]
114114
def to_sorbet_type
115-
case values
115+
types = values.map { Lithic::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
116+
case types
116117
in []
117118
T.noreturn
118-
in [value, *_]
119-
T.all(Lithic::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(value), self)
119+
in [type]
120+
type
121+
else
122+
T.any(*types)
120123
end
121124
end
122125

lib/lithic/internal/type/union.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,14 @@ def dump(value, state:)
206206
#
207207
# @return [Object]
208208
def to_sorbet_type
209-
case (v = variants)
209+
types = variants.map { Lithic::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
210+
case types
210211
in []
211212
T.noreturn
213+
in [type]
214+
type
212215
else
213-
T.any(*v.map { Lithic::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) })
216+
T.any(*types)
214217
end
215218
end
216219

lib/lithic/models.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ module Lithic
1111
mod.constants.each do |name|
1212
case mod.const_get(name)
1313
in true | false
14-
mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T.all(T::Boolean, mod) } }
14+
mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T::Boolean } }
1515
mod.define_sorbet_constant!(:OrBoolean) { T.type_alias { T::Boolean } }
1616
in Integer
17-
mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { T.all(Integer, mod) } }
17+
mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { Integer } }
1818
mod.define_sorbet_constant!(:OrInteger) { T.type_alias { Integer } }
1919
in Float
20-
mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { T.all(Float, mod) } }
20+
mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { Float } }
2121
mod.define_sorbet_constant!(:OrFloat) { T.type_alias { Float } }
2222
in Symbol
23-
mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { T.all(Symbol, mod) } }
23+
mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { Symbol } }
2424
mod.define_sorbet_constant!(:OrSymbol) { T.type_alias { T.any(Symbol, String) } }
2525
else
2626
end

0 commit comments

Comments
 (0)