Skip to content

Commit

Permalink
sorbet-runtime: Add some .checked(:tests) debug information (#4452)
Browse files Browse the repository at this point in the history
* sorbet-runtime: Add some .checked(:tests) debug information

* Update gems/sorbet-runtime/lib/types/private/methods/_methods.rb

Co-authored-by: Nathan Froyd <froydnj@gmail.com>

Co-authored-by: Nathan Froyd <froydnj@gmail.com>
  • Loading branch information
jez and froydnj committed Aug 4, 2021
1 parent d1323e0 commit c30aac1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gems/sorbet-runtime/lib/types/private/methods/_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ def self.run_all_sig_blocks
end
end

def self.all_checked_tests_sigs
@signatures_by_method.values.select {|sig| sig.check_level == :tests}
end

# the module target is adding the methods from the module source to itself. we need to check that for all instance
# methods M on source, M is not defined on any of target's ancestors.
def self._hook_impl(target, singleton_class, source)
Expand Down
5 changes: 4 additions & 1 deletion gems/sorbet-runtime/lib/types/private/runtime_levels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def self.check_tests?

def self.enable_checking_in_tests
if !@check_tests && @wrapped_tests_with_validation
all_checked_tests_sigs = T::Private::Methods.all_checked_tests_sigs
locations = all_checked_tests_sigs.map {|sig| sig.method.source_location.join(':')}.join("\n- ")
raise "Toggle `:tests`-level runtime type checking earlier. " \
"There are already some methods wrapped with `sig.checked(:tests)`." \
"There are already some methods wrapped with `sig.checked(:tests)`:\n" \
"- #{locations}"
end

_toggle_checking_tests(true)
Expand Down

0 comments on commit c30aac1

Please sign in to comment.