Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default if factory prop is set #833

Merged
merged 1 commit into from Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tapioca/gem/listeners/sorbet_props.rb
Expand Up @@ -19,7 +19,7 @@ def on_scope(event)
constant.props.map do |name, prop|
type = prop.fetch(:type_object, "T.untyped").to_s.gsub(".returns(<VOID>)", ".void")

default = prop.key?(:default) ? "T.unsafe(nil)" : nil
default = prop.key?(:default) || prop.key?(:factory) ? "T.unsafe(nil)" : nil
node << if prop.fetch(:immutable, false)
RBI::TStructConst.new(name.to_s, type, default: default)
else
Expand Down
2 changes: 2 additions & 0 deletions spec/tapioca/gem/pipeline_spec.rb
Expand Up @@ -2459,6 +2459,7 @@ class Bar < T::Struct
prop :bar, String
const :baz, T::Hash[String, T.untyped]
prop :quux, T.untyped, default: [1, 2, 3]
const :quuz, Integer, factory: -> { 1 }
end
RUBY

Expand Down Expand Up @@ -2602,6 +2603,7 @@ class Bar < ::T::Struct
const :baz, T::Hash[::String, T.untyped]
const :foo, ::Integer
prop :quux, T.untyped, default: T.unsafe(nil)
const :quuz, ::Integer, default: T.unsafe(nil)
class << self
def inherited(s); end
Expand Down