Skip to content

Commit ff52f6b

Browse files
authored
Merge branch 'master' into codex/rewriter-line-endings
2 parents 66e559d + 716ca05 commit ff52f6b

18 files changed

Lines changed: 99 additions & 99 deletions

File tree

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
GIT
22
remote: https://github.com/soutaro/steep.git
3-
revision: 2a52643c6554c553cd0dc31a6daef717304c3985
3+
revision: 3b75b367c9ad3d07f8f053c0c1f28e4bab560f5d
44
specs:
5-
steep (2.1.0.dev.1)
5+
steep (2.1.0)
66
concurrent-ruby (>= 1.1.10)
77
csv (>= 3.0.9)
88
fileutils (>= 1.1.0)
@@ -13,7 +13,7 @@ GIT
1313
parser (>= 3.2)
1414
prism (>= 0.25.0)
1515
rainbow (>= 2.2.2, < 4.0)
16-
rbs (~> 4.0)
16+
rbs (~> 4.2)
1717
securerandom (>= 0.1)
1818
strscan (>= 1.0.0)
1919
terminal-table (>= 2, < 5)
@@ -97,7 +97,7 @@ GEM
9797
prism (~> 1.5)
9898
minitest-mock (5.27.0)
9999
mutex_m (0.3.0)
100-
net-protocol (0.2.2)
100+
net-protocol (0.3.0)
101101
timeout
102102
net-smtp (0.5.1)
103103
net-protocol

Steepfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ target :lib do
2424
signature "stdlib/rdoc/0/"
2525
signature "stdlib/ripper/0"
2626
signature "stdlib/pp/0"
27-
signature "steep/patch.rbs"
2827

2928
# configure_code_diagnostics do |config|
3029
# config[D::Ruby::MethodDefinitionMissing] = :hint

lib/rbs/definition_builder.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ def source_location(source, decl)
504504
def validate_type_params(definition, ancestors:, methods:)
505505
type_params = definition.type_params_decl
506506

507+
# Without type params nothing can violate the variance: the ancestor validation
508+
# iterates the (empty) params, and the type params of the methods themselves are
509+
# invariant, which `Result#compatible?` always accepts
510+
return if type_params.empty?
511+
507512
calculator = VarianceCalculator.new(builder: self)
508513
param_names = type_params.each.map(&:name)
509514

@@ -1048,9 +1053,10 @@ def validate_type_presence(type)
10481053
end
10491054

10501055
def validate_type_name(name, location)
1051-
name = name.absolute! unless name.absolute?
1052-
return if env.type_name?(env.normalize_type_name(name))
1056+
absolute = name.absolute? ? name : name.absolute!
1057+
return if env.type_name?(env.normalize_type_name(absolute))
10531058

1059+
# Report the name as it is written in the signature
10541060
raise NoTypeFoundError.new(type_name: name, location: location)
10551061
end
10561062
end

lib/rbs/definition_builder/method_builder.rb

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,47 @@ def validate!
4646
self
4747
end
4848

49-
def each
50-
if block_given?
51-
Sorter.new(methods).each_strongly_connected_component do |scc|
52-
if scc.size > 1
53-
raise RecursiveAliasDefinitionError.new(type: type, defs: scc)
49+
def each(&block)
50+
if block
51+
# Yields the original method of an alias before the alias, like the
52+
# topological sort did, and detects recursive alias definitions on the way
53+
if methods.each_value.any? {|defn| defn.original.is_a?(AST::Members::Alias) }
54+
done = {} #: Hash[Definition, bool]
55+
done.compare_by_identity
56+
methods.each_value do |defn|
57+
each_alias_first(defn, done, [], &block)
5458
end
55-
56-
yield scc[0]
59+
else
60+
methods.each_value(&block)
5761
end
5862
else
5963
enum_for :each
6064
end
6165
end
6266

63-
class Sorter
64-
include TSort
67+
private
6568

66-
attr_reader :methods
69+
def each_alias_first(defn, done, visiting, &block)
70+
return if done[defn]
6771

68-
def initialize(methods)
69-
@methods = methods
72+
if visiting.any? {|other| other.equal?(defn) }
73+
index = visiting.index {|other| other.equal?(defn) } or raise
74+
raise RecursiveAliasDefinitionError.new(type: type, defs: visiting[index..] || raise)
7075
end
7176

72-
def tsort_each_node(&block)
73-
methods.each_value(&block)
74-
end
75-
76-
def tsort_each_child(defn)
77-
if (member = defn.original).is_a?(AST::Members::Alias)
78-
if old = methods[member.old_name]
79-
yield old
77+
if (member = defn.original).is_a?(AST::Members::Alias)
78+
if old = methods.fetch(member.old_name, nil)
79+
# A self alias forms a size-1 SCC that the topological sort yielded as is
80+
unless old.equal?(defn)
81+
visiting.push(defn)
82+
each_alias_first(old, done, visiting, &block)
83+
visiting.pop
8084
end
8185
end
8286
end
87+
88+
done[defn] = true
89+
yield defn
8390
end
8491
end
8592

lib/rbs/environment/class_entry.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def initialize(name)
1515
def <<(context_decl)
1616
context_decls << context_decl
1717
@primary_decl = nil
18+
@type_params_validated = nil
1819
self
1920
end
2021

@@ -50,6 +51,10 @@ def type_params
5051
end
5152

5253
def validate_type_params
54+
# The entry only changes with `<<`, which resets the memo -- a failed
55+
# validation is not recorded and raises again
56+
return if @type_params_validated
57+
5358
unless context_decls.empty?
5459
first_decl, *rest_decls = each_decl.to_a
5560
first_decl or raise
@@ -63,6 +68,8 @@ def validate_type_params
6368
end
6469
end
6570
end
71+
72+
@type_params_validated = true
6673
end
6774

6875
def align_params(decl)

lib/rbs/environment/module_entry.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def initialize(name)
1414

1515
def <<(context_decl)
1616
context_decls << context_decl
17+
@type_params_validated = nil
1718
self
1819
end
1920

@@ -72,6 +73,10 @@ def align_params(decl)
7273
end
7374

7475
def validate_type_params
76+
# The entry only changes with `<<`, which resets the memo -- a failed
77+
# validation is not recorded and raises again
78+
return if @type_params_validated
79+
7580
unless context_decls.empty?
7681
first_decl, *rest_decls = each_decl.to_a
7782
first_decl or raise
@@ -85,6 +90,8 @@ def validate_type_params
8590
end
8691
end
8792
end
93+
94+
@type_params_validated = true
8895
end
8996
end
9097
end

lib/rbs/method_type.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ def has_classish_type?
129129
end
130130

131131
def with_nonreturn_void?
132-
if type.with_nonreturn_void? # steep:ignore DeprecatedReference
132+
if type.with_nonreturn_void?
133133
true
134134
else
135135
if block = block()
136-
block.type.with_nonreturn_void? || # steep:ignore DeprecatedReference
137-
block.self_type&.with_nonreturn_void? || # steep:ignore DeprecatedReference
136+
block.type.with_nonreturn_void? ||
137+
block.self_type&.with_nonreturn_void? ||
138138
false
139139
else
140140
false

lib/rbs/prototype/helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Helpers
66
private
77

88
def parse_comments(string, include_trailing:)
9-
Prism.parse_comments(string, version: "current").yield_self do |prism_comments| # steep:ignore UnexpectedKeywordArgument
9+
Prism.parse_comments(string, version: "current").yield_self do |prism_comments|
1010
prism_comments.each_with_object({}) do |comment, hash| #$ Hash[Integer, AST::Comment]
1111
# Skip EmbDoc comments
1212
next unless comment.is_a?(Prism::InlineComment)

lib/rbs/types.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def with_nonreturn_void?
251251
# `void` in immediate generics parameter is allowed
252252
false
253253
else
254-
type.with_nonreturn_void? # steep:ignore DeprecatedReference
254+
type.with_nonreturn_void?
255255
end
256256
end
257257
end
@@ -530,7 +530,7 @@ def has_classish_type?
530530
end
531531

532532
def with_nonreturn_void?
533-
each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
533+
each_type.any? {|type| type.with_nonreturn_void? }
534534
end
535535
end
536536

@@ -648,7 +648,7 @@ def has_classish_type?
648648
end
649649

650650
def with_nonreturn_void?
651-
each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
651+
each_type.any? {|type| type.with_nonreturn_void? }
652652
end
653653
end
654654

@@ -734,7 +734,7 @@ def has_classish_type?
734734
end
735735

736736
def with_nonreturn_void?
737-
each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
737+
each_type.any? {|type| type.with_nonreturn_void? }
738738
end
739739
end
740740

@@ -825,7 +825,7 @@ def has_classish_type?
825825
end
826826

827827
def with_nonreturn_void?
828-
each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
828+
each_type.any? {|type| type.with_nonreturn_void? }
829829
end
830830
end
831831

@@ -908,7 +908,7 @@ def has_classish_type?
908908
end
909909

910910
def with_nonreturn_void?
911-
each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
911+
each_type.any? {|type| type.with_nonreturn_void? }
912912
end
913913
end
914914

@@ -1278,13 +1278,13 @@ def has_classish_type?
12781278
end
12791279

12801280
def with_nonreturn_void?
1281-
if each_param.any? {|param| param.type.with_nonreturn_void? } # steep:ignore DeprecatedReference
1281+
if each_param.any? {|param| param.type.with_nonreturn_void? }
12821282
true
12831283
else
12841284
if return_type.is_a?(Bases::Void)
12851285
false
12861286
else
1287-
return_type.with_nonreturn_void? # steep:ignore DeprecatedReference
1287+
return_type.with_nonreturn_void?
12881288
end
12891289
end
12901290
end
@@ -1557,11 +1557,11 @@ def has_classish_type?
15571557
end
15581558

15591559
def with_nonreturn_void?
1560-
if type.with_nonreturn_void? || self_type&.with_nonreturn_void? # steep:ignore DeprecatedReference
1560+
if type.with_nonreturn_void? || self_type&.with_nonreturn_void?
15611561
true
15621562
else
15631563
if block = block()
1564-
block.type.with_nonreturn_void? || block.self_type&.with_nonreturn_void? || false # steep:ignore DeprecatedReference
1564+
block.type.with_nonreturn_void? || block.self_type&.with_nonreturn_void? || false
15651565
else
15661566
false
15671567
end

sig/environment/class_entry.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module RBS
1818

1919
@primary_decl: declaration?
2020

21+
@type_params_validated: bool?
22+
2123
def initialize: (TypeName) -> void
2224

2325
def <<: (context_decl) -> self

0 commit comments

Comments
 (0)