Open
Description
Input
# typed: true
extend T::Sig
my_boolean = rand(10).even?
boolean_tap_result = my_boolean.tap { puts "Do nothing" }
T.reveal_type(boolean_tap_result) # <== TrueClass!?
MyUnionType = T.type_alias { T.any(String, Integer) }
union_type_instance =
if rand(10).even?
"Hey there!"
else
1
end
union_type_tap_result = union_type_instance.tap { puts "Do nothing" }
T.reveal_type(union_type_tap_result) # <== Integer!?
Observed output
editor.rb:7: Revealed type: TrueClass https://srb.help/7014
7 |T.reveal_type(boolean_tap_result) # <== TrueClass!?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Got TrueClass originating from:
editor.rb:6:
6 |boolean_tap_result = my_boolean.tap { puts "Do nothing" }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
editor.rb:20: Revealed type: Integer https://srb.help/7014
20 |T.reveal_type(union_type_tap_result) # <== Integer!?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Got Integer originating from:
editor.rb:19:
19 |union_type_tap_result = union_type_instance.tap { puts "Do nothing" }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 2
Expected behavior
The T.self_type
should respect the union type. So instead of just retuning a (random?!) type from the union, it should return the whole union type definition.