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: strictextendT::Sigsig{returns(T.any(Integer,String))}defdo_some_stuffresult=T.let(nil,T.nilable(T.any(Integer,String)))value=rand(10)ifvalue.even?returnresult=valueendresult="Invalid value generated"ensurecaseresultwhennilputs"Nil returned"whenIntegerputs"Integer returned"whenStringputs"String returned"elseT.absurd(result)endend
Observed output
editor.rb:20: This code is unreachable https://srb.help/7006
20 | puts "Integer returned"
^^^^^^^^^^^^^^^^^^^^^^^
editor.rb:19: This condition was always falsy (FalseClass)
19 | when Integer
^^^^^^^
Got FalseClass originating from:
editor.rb:19:
19 | when Integer
^^^^^^^
Errors: 1
Expected behavior
The code should work as expected since, when the code execution reaches the ensure block the variable can have either String or Integer value (even nil in case an error happens). Apparently the current code just takes the last assignment to the variable and treat that as the truth about the variable's value.
The text was updated successfully, but these errors were encountered:
Input
→ View on sorbet.run
Observed output
Expected behavior
The code should work as expected since, when the code execution reaches the
ensure
block the variable can have eitherString
orInteger
value (evennil
in case an error happens). Apparently the current code just takes the last assignment to the variable and treat that as the truth about the variable's value.The text was updated successfully, but these errors were encountered: