CodeSampleX

Пример

sorbet-runtime 0.6.13427: Show that `sig(:final)` is not automatically enforced across module/class boundaries unless final checks are explicitly enabled for hooks.

Проверенный пример — gem sorbet-runtime 0.6.13427: Show that `sig(:final)` is not automatically enforced across module/class boundaries unless final checks…

sha256:2e94d74152f032eab543576cbea98419ba9217c867306dbd5f697661a0895a03

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
2
Заявленная среда ruby linux x64 ruby ruby bundle

Среды запусков проверки

Окружение Контракт Этапы Запуск
ruby 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · rubygems@1
2026-08-17
ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · rubygems@1
2026-08-18

Кейс

HOW
Цель
Show that `sig(:final)` is not automatically enforced across module/class boundaries unless final checks are explicitly enabled for hooks.
Пакеты
Символы
  • T::Sig
  • T::Configuration
Окружение
ruby
Создан
2026-08-17T02:48:33Z

Контракт

  1. Overriding a `sig(:final)` method by defining the same instance method in a class after including a module with that final method succeeds while final checks are not enabled.
  2. Enabling final checks on hooks converts the same pattern into a class-definition-time failure when a class includes a final method module and then defines that method.

Файлы

  • Gemfile
  • Gemfile.lock
  • NOTES.md
  • csx.json
  • test/contract.rb

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

Gemfile
source "https://rubygems.org"

gem "sorbet-runtime", "0.6.13427"
Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    sorbet-runtime (0.6.13427)

PLATFORMS
  ruby
  x64-mingw-ucrt

DEPENDENCIES
  sorbet-runtime (= 0.6.13427)

CHECKSUMS
  bundler (4.0.18) sha256=02d9a17429de1847b4e0c9f27a9ee4b20c0a74c0a641b4e77195d6019e3618ac
  sorbet-runtime (0.6.13427) sha256=62ceb3186afd62694bf854a455adb00f6804291b44eba8554b357b9fb93a9275

BUNDLED WITH
  4.0.18
NOTES.md
`search_known_solution` returned a REFERENCE_ONLY hit for `case:sha256:1e71c5f79073d471042387f5760bd6c816cdae76e4f94fd229b1aa9c4b34d25d` (a different trap about runtime shallow signature checks), so this sample uses the `sig(:final)` + `enable_final_checks_on_hooks` interaction instead.

On a version without enforced final hooks (or if the feature is never enabled), the second contract line would pass silently with a green build, hiding the override violation.
csx.json
{"case":{"believed":"A method marked with `sig(:final)` is always rejected when a class overrides it through include.","caseId":"case:sha256:9d252e174b689fee7e67f9e94bf33fe8b53fdea9cba7623c60214b700047f829","contract":["Overriding a `sig(:final)` method by defining the same instance method in a class after including a module with that final method succeeds while final checks are not enabled.","Enabling final checks on hooks converts the same pattern into a class-definition-time failure when a class includes a final method module and then defines that method."],"goal":"Show that `sig(:final)` is not automatically enforced across module/class boundaries unless final checks are explicitly enabled for hooks.","kind":"HOW","packages":["pkg:gem/sorbet-runtime@0.6.13427"],"schemaVersion":1,"symbols":["T::Sig","T::Configuration"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"bundle","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/sorbet-runtime@0.6.13427"],"schemaVersion":1,"symbols":["T::Sig","T::Configuration"],"verifierAdapter":"rubygems@1"}
test/contract.rb
require "sorbet-runtime"

def assert(condition, message)
  raise "Assertion failed: #{message}" unless condition
end

# A final sig on a shared module is not rejected at runtime by default.
module BaselineFinalModule
  extend T::Sig

  sig(:final) { params(value: Integer).returns(Integer) }
  def final_value(value)
    value
  end
end

class BaselineOverride
  include BaselineFinalModule

  def final_value(value)
    value + 1
  end
end

assert(BaselineOverride.new.final_value(1) == 2, "default runtime allows overriding final sig'd methods via include")

# Enabling final checks on hooks makes that override fail at definition time.
T::Configuration.enable_final_checks_on_hooks

module HookCheckedFinalModule
  extend T::Sig

  sig(:final) { params(value: Integer).returns(Integer) }
  def final_value(value)
    value
  end
end

hook_error = nil
begin
  class HookCheckedOverride
    include HookCheckedFinalModule

    def final_value(value)
      value + 1
    end
  end
rescue => error
  hook_error = error
end

assert(!hook_error.nil?, "including an override module after enabling hook checks raises a runtime error")
assert(hook_error.is_a?(RuntimeError), "the failure is reported as RuntimeError")

Исходный сидер

csx-seed