You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# typed: trueextendT::SigclassKind < T::EnumenumsdoX=newY=newendendclassFoo < T::Structprop:type,KindendclassBar < T::Structprop:type,Kind::X,default: Kind::Xenda=Foo.new(type: Kind::X).serialize# {"type"=>"x"}b=Bar.new.serialize# {"type"=>#<Foo::X>}# $ a == b# true## Which makes sense, because Kind::X == "x"
Bar should be serialized identically to Foo. The only difference that Bar has to Foo, is that Bar only allows Kind::X to be passed, whereas Foo allows any value in Kind.
qaisjp
changed the title
Enum class struct props serialized differently enum members themselves
Enum class struct props serialized differently to enum members themselves
Jan 11, 2022
qaisjp
changed the title
Enum class struct props serialized differently to enum members themselves
Enum class struct props serialized differently to enum values
Jan 11, 2022
It looks like we only do handle_custom_type for the T::Types::Simple case. Sorbet stores the Kind::X types as T::Types::TEnum types, which are not T::Types::Simple
So we need to add a case for T::Types::TEnum, and call handle_custom_type in it.
Also worth noting: I'm not 100% sure that the above file is the only place that the serde code lives in sorbet-runtime right now—it might be duplicated in both the dynamically-generated serde methods as well as another, equivalent place that doesn't use eval, so we would want to double check that.
Input
→ View on sorbet.run
Observed output
Expected behavior
Bar
should be serialized identically toFoo
. The only difference thatBar
has toFoo
, is thatBar
only allowsKind::X
to be passed, whereasFoo
allows any value inKind
.The text was updated successfully, but these errors were encountered: