Skip to content

Commit

Permalink
Merge pull request #2016 from ruby/type-check
Browse files Browse the repository at this point in the history
Fix type definition and type errors
  • Loading branch information
soutaro committed Sep 18, 2024
2 parents d71bb51 + f4c2b7e commit bc6ee45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/rbs/prototype/rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def range_element_type(types)

types = types.map do |t|
if t.is_a?(Types::Literal)
type_name = TypeName.new(name: t.literal.class.name.to_sym, namespace: Namespace.root)
type_name = TypeName.new(name: t.literal.class.name&.to_sym || raise, namespace: Namespace.root)
Types::ClassInstance.new(name: type_name, args: [], location: nil)
else
t
Expand Down Expand Up @@ -825,7 +825,7 @@ def sort_members!(decls)
AST::Members::ClassVariable => -3,
AST::Members::ClassInstanceVariable => -2,
AST::Members::InstanceVariable => -1,
}
} #: Hash[Class, Integer]
decls.sort_by! { |decl| [orders.fetch(decl.class, 0), i += 1] }
end
end
Expand Down
17 changes: 12 additions & 5 deletions sig/types.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,23 @@ module RBS
end

class Record
attr_reader all_fields: Hash[Symbol, [t, bool]]
type key = Symbol | String | Integer | bool

attr_reader fields: Hash[Symbol, t]
# All types of all files
#
# If the key is *required*, the second value of the tuple is `true`.
# If the key is *optional*, the second value of the tuple is `false`.
#
attr_reader all_fields: Hash[key, [t, bool]]

attr_reader fields: Hash[key, t]

attr_reader optional_fields: Hash[Symbol, t]
attr_reader optional_fields: Hash[key, t]

type loc = Location[bot, bot]

def initialize: (fields: Hash[Symbol, t], location: loc?) -> void
| (all_fields: Hash[Symbol, [t, bool]], location: loc?) -> void
def initialize: (fields: Hash[key, t], location: loc?) -> void
| (all_fields: Hash[key, [t, bool]], location: loc?) -> void

include _TypeBase

Expand Down

0 comments on commit bc6ee45

Please sign in to comment.