# typed: true
module Foo
def bar
raise 'foo'
end
end
class Fooer
include Foo
end
Fooer.new.bar # Raises an error when run
editor.rb:4: Method raise does not exist on Foo https://srb.help/7003
4 | raise 'foo'
^^^^^^^^^^^
Did you mean to `include Kernel` in this module?
https://github.com/sorbet/sorbet/tree/90c20f728c528aa4a1a3dc1a137e4c9eae95716d/rbi/core/kernel.rbi#L870: Did you mean: Kernel#raise?
870 | def raise(arg0=T.unsafe(nil), arg1=T.unsafe(nil), arg2=T.unsafe(nil)); end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 1
In real execution this code is perfectly valid, the call to the mixed-in method will raise an error.
No error when running typecheck
Depending on the underlying system, this may be the same root cause as https://github.com/sorbet/sorbet/issues/397
You should just need to include Kernel in the definition of module Foo to resolve this error during typechecking. For more information, see including kernel
@elliottt Thanks for linking to that trouble shooting doc, my searching focused on others having the issue with raise not Kernel.
@bmalinconico The reason why it is this way is because this would fail at runtime (note the subclassing from BasicObject here):
# typed: true
module Foo
def bar
raise 'foo'
end
end
class Baz < BasicObject
include ::Foo
end
Baz.new.bar
Basically, Sorbet cannot guarantee that the module would always be included into something that inherits from Object, so it tries to be safe.
Because this is expected, documented behavior, I'm closing.