Skip to content

Commit 60be129

Browse files
authored
Merge pull request #3137 from OskarEichler/codex/optional-record-fields
Validate present optional record fields at runtime
2 parents 25fff99 + fa6a329 commit 60be129

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/rbs/test/type_check.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,10 @@ def value(val, type)
376376
type.types.map.with_index {|ty, index| value(val[index], ty) }.all?
377377
when Types::Record
378378
Test::call(val, IS_AP, ::Hash) &&
379-
type.fields.map {|key, type| value(val[key], type) }.all?
379+
type.fields.all? {|key, type| value(val[key], type) } &&
380+
type.optional_fields.all? do |key, type|
381+
!val.key?(key) || value(val[key], type)
382+
end
380383
when Types::Proc
381384
Test::call(val, IS_AP, ::Proc)
382385
else

0 commit comments

Comments
 (0)