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

Fix type definition and type errors #2016

Merged
merged 2 commits into from
Sep 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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