I was looking through the list of Sorbet runtime errors from the docs. It seems to me that "Errors from invalid sig procs" and "Errors from invalid sigs" would be caught by the Sorbet type checker. If your code passes Sorbet's static checks, is it guaranteed that those runtime errors would never occur?
There are cases in which the static checks pass, but you'd get a runtime error. Consider the following:
# typed: strict
class A
extend T::Sig
sig {returns(Integer)}
def foo; 0; end
end
class B < A
sig {returns(String)}
def foo; '0'; end
end
B.new.foo
Running this will end up in:
RuntimeError: Incompatible return type in signature for override of method `foo`
You can avoid falling in this by making sure that you use overridable or (:final) (docs) in your signatures when appropriate.
class A
extend T::Sig
sig {overridable.returns(Integer)}
def foo; 0; end
sig (:final) {returns(Integer)}
def bar; 0; end
end
class B < A
sig {returns(String)} # this will fail static check, as it doesn't declare `override`
def foo; '0'; end
sig {returns(String)} # this will fail static check, as `bar` is `final`
def bar; '0'; end
end