Skip to content

Commit

Permalink
Set default if factory prop is set
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcarbs committed Feb 28, 2022
1 parent 8ae32f0 commit 48e32af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
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

0 comments on commit 48e32af

Please sign in to comment.