Skip to content

Commit 14c7e56

Browse files
fix: to_sorbet_type should not return branded types
1 parent 0369cd3 commit 14c7e56

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/orb/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 { Orb::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
116+
case types
116117
in []
117118
T.noreturn
118-
in [value, *_]
119-
T.all(Orb::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/orb/internal/type/union.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,14 @@ def dump(value, state:)
235235
#
236236
# @return [Object]
237237
def to_sorbet_type
238-
case (v = variants)
238+
types = variants.map { Orb::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
239+
case types
239240
in []
240241
T.noreturn
242+
in [type]
243+
type
241244
else
242-
T.any(*v.map { Orb::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) })
245+
T.any(*types)
243246
end
244247
end
245248

lib/orb/models.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ module Orb
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)