Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Dec 20, 2021
1 parent 1069c87 commit 9bb4613
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/rbs/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ def validate_type_alias(entry:)
end

validate_type_params(
type_name,
nil,
entry.decl.type_params,
type_name: type_name,
location: entry.decl.location&.aref(:type_params)
)
end
end

def validate_type_params(type_name, method_name, params, location:)
def validate_type_params(params, type_name: , method_name: nil, location:)
# @type var each_node: TSort::_EachNode[Symbol]
each_node = __skip__ = -> (&block) do
params.each do |param|
Expand Down
20 changes: 18 additions & 2 deletions sig/validator.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,29 @@ module RBS

# Validates type alias definition:
#
# *
# - There is no circular definition between aliases
# - The type alias is _regular_
# - The generics type parameter variance annotation is consistent with respect to their usage
# - There is no circular dependencies between the generics type parameter bounds
#
def validate_type_alias: (entry: Environment::SingleEntry[TypeName, AST::Declarations::Alias]) -> void

def validate_type_params: (TypeName type_name, Symbol? method_name, Array[AST::TypeParam] params, location: Location[untyped, untyped]?) -> void
# Validates the type parameters if there is no circular dependencies between the bounds.
#
# ```rbs
# [X, Y] # OK
# [X, Y < _Foo[X]] # OK
# [X < _Foo[Y], Y] # OK
# [X < _Foo[Y], Y < _Foo[X]] # Error
# ```
#
def validate_type_params: (Array[AST::TypeParam] params, type_name: TypeName, ?method_name: Symbol?, location: Location[untyped, untyped]?) -> void

private

# Resolves relative type names to absolute type names in given context.
# Yields the type when the type name resolution using `#resolver` fails.
#
def absolute_type: (Types::t, context: TypeNameResolver::context) { (Types::t) -> TypeName } -> Types::t
end
end

0 comments on commit 9bb4613

Please sign in to comment.