Skip to content

Instantly share code, notes, and snippets.

@packrat386
Last active December 21, 2020 21:04
Show Gist options
  • Save packrat386/641e0e204f8db72d10502c03a04a31ea to your computer and use it in GitHub Desktop.
Save packrat386/641e0e204f8db72d10502c03a04a31ea to your computer and use it in GitHub Desktop.
tricking sorbet
[acoyle01] wat > bundle exec srb tc
village.rb:13: This code is unreachable https://srb.help/7006
13 | raise "gtfo #{participant}"
^^^^^^^^^^^^^^^^^^^^^
Errors: 1
[acoyle01] wat > bundle exec ruby village.rb
time for the festival
#<Human:0x000055d9d0f03598> got wine
Traceback (most recent call last):
3: from village.rb:53:in `<main>'
2: from /home/acoyle/.gem/ruby/2.7.1/gems/sorbet-runtime-0.5.6173/lib/types/private/methods/call_validation.rb:354:in `block in create_validator_method_fast1'
1: from /home/acoyle/.gem/ruby/2.7.1/gems/sorbet-runtime-0.5.6173/lib/types/private/methods/call_validation.rb:354:in `call'
village.rb:13:in `add_to_feast': gtfo #<Changeling:0x000055d9d0f02af8> (RuntimeError)
# typed: true
require 'rubygems'
require 'bundler/setup'
require 'sorbet-runtime'
class Village
extend T::Sig
sig {params(participant: Human).returns(NilClass)}
def add_to_feast(participant)
if !participant.kind_of?(Human)
raise "gtfo #{participant}"
end
participant.give("wine")
nil
end
end
class Human
def give(thing)
puts "#{self} got #{thing}"
end
end
class Changeling
def is_a?(*)
true
end
def give(thing)
puts "#{self} got #{thing}"
end
end
v = Village.new
h = Human.new
puts "time for the festival"
v.add_to_feast(h)
class Human
def self.new
Changeling.new
end
end
c = Human.new
v.add_to_feast(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment