Incorrect unreachable code error when using `Class.new` inside method body · Issue #6568 · sorbet/sorbet · GitHub
More Web Proxy on the site http://driver.im/
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: truerequire'sorbet-runtime'extendT::Sig# With this commented out, sorbet reports no errors. Either# way, the script prints Created record #<MyARModel:0x000000011f125d70># as expecteddefstuffClass.newdodefcallendendendclassMyARModelextendT::Sigsig{params(attributes: T.untyped,block: T.nilable(T.proc.params(object: ::MyARModel).void)).returns(::MyARModel)}defself.find_or_create_by(attributes, &block)model=MyARModel.newunlessblock.nil?yieldmodelendmodelendendMyARModel.find_or_create_by(foo: "bar",baz: "baf")do |record|
puts"Created record #{record}"end
Observed output
editor.rb:28: This code is unreachable https://srb.help/7006
28 |MyARModel.find_or_create_by(foo: "bar", baz: "baf") do |record|
^^^^^^
editor.rb:28: This expression always raises or can never be computed
28 |MyARModel.find_or_create_by(foo: "bar", baz: "baf") do |record|
29 | puts "Created record #{record}"
30 |end
Errors: 1
this looks like a bug. i’m guessing this regression was caused by this change #5503
The text was updated successfully, but these errors were encountered:
jez
changed the title
Incorrect unreachable code error when codebase contains certain call method implementations
Incorrect unreachable code error when using Class.new inside method body
Nov 17, 2022
Input
→ View on sorbet.run
Observed output
Expected behavior
Sorbet shouldn't report any errors for this code.
Discussion in Slack. Context from @jez:
The text was updated successfully, but these errors were encountered: