Skip to content
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
10 changes: 8 additions & 2 deletions lib/rbs/definition_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ def source_location(source, decl)
def validate_type_params(definition, ancestors:, methods:)
type_params = definition.type_params_decl

# Without type params nothing can violate the variance: the ancestor validation
# iterates the (empty) params, and the type params of the methods themselves are
# invariant, which `Result#compatible?` always accepts
return if type_params.empty?

calculator = VarianceCalculator.new(builder: self)
param_names = type_params.each.map(&:name)

Expand Down Expand Up @@ -1048,9 +1053,10 @@ def validate_type_presence(type)
end

def validate_type_name(name, location)
name = name.absolute! unless name.absolute?
return if env.type_name?(env.normalize_type_name(name))
absolute = name.absolute? ? name : name.absolute!
return if env.type_name?(env.normalize_type_name(absolute))

# Report the name as it is written in the signature
raise NoTypeFoundError.new(type_name: name, location: location)
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/rbs/environment/class_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize(name)
def <<(context_decl)
context_decls << context_decl
@primary_decl = nil
@type_params_validated = nil
self
end

Expand Down Expand Up @@ -50,6 +51,10 @@ def type_params
end

def validate_type_params
# The entry only changes with `<<`, which resets the memo -- a failed
# validation is not recorded and raises again
return if @type_params_validated

unless context_decls.empty?
first_decl, *rest_decls = each_decl.to_a
first_decl or raise
Expand All @@ -63,6 +68,8 @@ def validate_type_params
end
end
end

@type_params_validated = true
end

def align_params(decl)
Expand Down
7 changes: 7 additions & 0 deletions lib/rbs/environment/module_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def initialize(name)

def <<(context_decl)
context_decls << context_decl
@type_params_validated = nil
self
end

Expand Down Expand Up @@ -72,6 +73,10 @@ def align_params(decl)
end

def validate_type_params
# The entry only changes with `<<`, which resets the memo -- a failed
# validation is not recorded and raises again
return if @type_params_validated

unless context_decls.empty?
first_decl, *rest_decls = each_decl.to_a
first_decl or raise
Expand All @@ -85,6 +90,8 @@ def validate_type_params
end
end
end

@type_params_validated = true
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/environment/class_entry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module RBS

@primary_decl: declaration?

@type_params_validated: bool?

def initialize: (TypeName) -> void

def <<: (context_decl) -> self
Expand Down
2 changes: 2 additions & 0 deletions sig/environment/module_entry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module RBS

attr_reader context_decls: Array[context_decl]

@type_params_validated: bool?

def initialize: (TypeName) -> void

def <<: (context_decl) -> self
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ module Bar[B]
cli.run(["-I", dir, "validate"])
end

assert_include stdout.string, "a.rbs:2:13...2:14: Could not find ::A (RBS::NoTypeFoundError)"
assert_include stdout.string, "a.rbs:2:13...2:14: Could not find A (RBS::NoTypeFoundError)"
end
end
end
Expand Down
Loading