Skip to content

Commit

Permalink
Properly handle falsey defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-mannino committed Nov 19, 2024
1 parent 53ac0df commit a3e2485
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/inexact_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def sorted_parameters
def parameters
constant.props.map do |name, prop|
type = prop.fetch(:type_object).to_s
if prop[:default]
if !prop[:default].nil?
create_kw_opt_param(name.to_s, type: type, default: 'T.unsafe(nil)')
elsif T::Props::Utils.optional_prop?(prop)
create_kw_opt_param(name.to_s, type: type, default: 'nil')
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/bar.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/inexact_struct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Foo < T::InexactStruct
class Bar < Foo
const :x, T::Boolean
const :y, T.nilable(String)
const :z, T.any(Integer, T::Boolean)
const :z, T.any(Integer, T::Boolean), default: false
end

class Baz < T::InexactStruct
Expand Down

0 comments on commit a3e2485

Please sign in to comment.