Skip to content

Commit 5e334ef

Browse files
authored
Merge pull request #2022 from ruby/default-type-self
Prohibit `self` type as a generics default
2 parents 5dfa097 + bbb885e commit 5e334ef

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ group :minitest do
4343
end
4444

4545
group :typecheck_test do
46-
gem "steep", "~> 1.7.1", require: false
46+
gem "steep", "~> 1.8.0.pre", require: false
4747
end

Gemfile.lock

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ GEM
1313
remote: https://rubygems.org/
1414
specs:
1515
abbrev (0.1.2)
16-
activesupport (7.1.4)
16+
activesupport (7.2.1)
1717
base64
1818
bigdecimal
19-
concurrent-ruby (~> 1.0, >= 1.0.2)
19+
concurrent-ruby (~> 1.0, >= 1.3.1)
2020
connection_pool (>= 2.2.5)
2121
drb
2222
i18n (>= 1.6, < 2)
23+
logger (>= 1.4.2)
2324
minitest (>= 5.1)
24-
mutex_m
25-
tzinfo (~> 2.0)
25+
securerandom (>= 0.3)
26+
tzinfo (~> 2.0, >= 2.0.5)
2627
addressable (2.8.7)
2728
public_suffix (>= 2.0.2, < 7.0)
2829
ast (2.4.2)
@@ -44,7 +45,7 @@ GEM
4445
psych (>= 3.1, < 5.0)
4546
rainbow (>= 3.0, < 4.0)
4647
strong_json (>= 1.1, < 2.2)
47-
i18n (1.14.5)
48+
i18n (1.14.6)
4849
concurrent-ruby (~> 1.0)
4950
json (2.7.2)
5051
json-schema (5.0.0)
@@ -119,7 +120,7 @@ GEM
119120
ruby-progressbar (1.13.0)
120121
securerandom (0.3.1)
121122
stackprof (0.2.26)
122-
steep (1.7.1)
123+
steep (1.8.0.pre.2)
123124
activesupport (>= 5.1)
124125
concurrent-ruby (>= 1.1.10)
125126
csv (>= 3.0.9)
@@ -130,7 +131,7 @@ GEM
130131
logger (>= 1.3.0)
131132
parser (>= 3.1)
132133
rainbow (>= 2.2.2, < 4.0)
133-
rbs (>= 3.5.0.pre)
134+
rbs (~> 3.6.0.pre)
134135
securerandom (>= 0.1)
135136
strscan (>= 1.0.0)
136137
terminal-table (>= 2, < 4)
@@ -180,7 +181,7 @@ DEPENDENCIES
180181
rubocop-on-rbs
181182
rubocop-rubycw
182183
stackprof
183-
steep (~> 1.7.1)
184+
steep (~> 1.8.0.pre)
184185
tempfile
185186
test-unit
186187

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ end
5656
task :validate => :compile do
5757
require 'yaml'
5858

59-
sh "#{ruby} #{rbs} validate"
59+
sh "#{ruby} #{rbs} validate --exit-error-on-syntax-error"
6060

6161
libs = FileList["stdlib/*"].map {|path| File.basename(path).to_s }
6262

@@ -72,7 +72,7 @@ task :validate => :compile do
7272
end
7373

7474
libs.each do |lib|
75-
sh "#{ruby} #{rbs} -r #{lib} validate"
75+
sh "#{ruby} #{rbs} -r #{lib} validate --exit-error-on-syntax-error"
7676
end
7777
end
7878

core/enumerator.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
132132

133133
# A convenience interface for `each` with optional block
134134
#
135-
interface _Each[out E, out R = self]
135+
interface _Each[out E, out R]
136136
def each: () { (E) -> void } -> R
137137
| () -> Enumerator[E, R]
138138
end

lib/rbs/cli/validate.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def validate_class_module_definition
165165

166166
if dt = param.default_type
167167
void_type_context_validator(dt, true)
168+
no_self_type_validator(dt)
168169
no_classish_type_validator(dt)
169170
@validator.validate_type(dt, context: nil)
170171
end
@@ -241,6 +242,7 @@ def validate_interface
241242

242243
if dt = param.default_type
243244
void_type_context_validator(dt, true)
245+
no_self_type_validator(dt)
244246
no_classish_type_validator(dt)
245247
@validator.validate_type(dt, context: nil)
246248
end

test/rbs/cli_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,16 +562,16 @@ class B[S = self]
562562
563563
interface _C[T = self]
564564
end
565-
RBS
566565
567-
(Pathname(dir) + 'b.rbs').write(<<~RBS)
568566
type t[T = self] = untyped
569567
RBS
570568

571569
cli.run(["-I", dir, "validate"])
572570

573-
refute_operator stdout.string, :include?, "/a.rbs"
574-
assert_include stdout.string, "/b.rbs:1:11...1:15: `self` type is not allowed in this context (RBS::WillSyntaxError)"
571+
assert_include stdout.string, "/a.rbs:1:13...1:17: `self` type is not allowed in this context (RBS::WillSyntaxError)\n"
572+
assert_include stdout.string, "/a.rbs:4:12...4:16: `self` type is not allowed in this context (RBS::WillSyntaxError)\n"
573+
assert_include stdout.string, "/a.rbs:7:17...7:21: `self` type is not allowed in this context (RBS::WillSyntaxError)\n"
574+
assert_include stdout.string, "/a.rbs:10:11...10:15: `self` type is not allowed in this context (RBS::WillSyntaxError)\n"
575575
end
576576
end
577577
end

0 commit comments

Comments
 (0)