You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# typed: strictclassShortcode < ApplicationRecordafter_initialize:set_defaults,if: :new_record?privatedefset_defaultsself.code ||= SecureRandom.urlsafe_base64(10)endend# == Schema Information## Table name: shortcodes## id :bigint not null, primary key# code :string not null# created_at :datetime not null# updated_at :datetime not null## Indexes## index_shortcodes_on_code (code) UNIQUE
Migration:
class CreateShortcodes < ActiveRecord::Migration[7.0]
def change
create_table :shortcodes do |t|
t.string :code, null: false
t.index :code, unique: true
t.timestamps
end
end
end
Annotation RBI (generated by tapioca):
class Shortcode
include GeneratedAttributeMethods
extend GeneratedRelationMethods
private
# cut for length
module GeneratedAttributeMethods
# cut for length
sig { returns(::String) }
def code; end
sig { params(value: ::String).returns(::String) }
def code=(value); end
sig { returns(T::Boolean) }
def code?; end
sig { returns(T.nilable(::String)) }
def code_before_last_save; end
sig { returns(T.untyped) }
def code_before_type_cast; end
sig { returns(T::Boolean) }
def code_came_from_user?; end
sig { returns(T.nilable([::String, ::String])) }
def code_change; end
sig { returns(T.nilable([::String, ::String])) }
def code_change_to_be_saved; end
sig { returns(T::Boolean) }
def code_changed?; end
sig { returns(T.nilable(::String)) }
def code_in_database; end
sig { returns(T.nilable([::String, ::String])) }
def code_previous_change; end
sig { returns(T::Boolean) }
def code_previously_changed?; end
sig { returns(T.nilable(::String)) }
def code_previously_was; end
sig { returns(T.nilable(::String)) }
def code_was; end
sig { void }
def code_will_change!; end
end
end
The check should have passed, because it is possible for self.short_code to be either nil or defined depending on how Shortcode.create! is called. You can call Shortcode.create!(code: "my_code") and create a record with code defined, and you can also call Shortcode.create! at which point line 7 above will assign a random code. The code is not unreachable.
Sorbet version: 0.5.10160
Tapioca version: 0.10.3
The text was updated successfully, but these errors were encountered:
Referred from sorbet/sorbet#6621
Input
Model:
Migration:
Annotation RBI (generated by
tapioca
):Observed output
Expected behavior
The check should have passed, because it is possible for
self.short_code
to be eithernil
or defined depending on howShortcode.create!
is called. You can callShortcode.create!(code: "my_code")
and create a record withcode
defined, and you can also callShortcode.create!
at which point line 7 above will assign a random code. The code is not unreachable.Sorbet version: 0.5.10160
Tapioca version: 0.10.3
The text was updated successfully, but these errors were encountered: