Skip to content

Commit 1e92eb5

Browse files
committed
Allow self types in generics default type
1 parent 061aa32 commit 1e92eb5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/rbs/cli/validate.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ 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)
169168
no_classish_type_validator(dt)
170169
@validator.validate_type(dt, context: nil)
171170
end
@@ -242,7 +241,6 @@ def validate_interface
242241

243242
if dt = param.default_type
244243
void_type_context_validator(dt, true)
245-
no_self_type_validator(dt)
246244
no_classish_type_validator(dt)
247245
@validator.validate_type(dt, context: nil)
248246
end

test/rbs/cli_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,32 @@ module X7 : A[String, untyped]
550550
end
551551
end
552552

553+
def test_validate__generics_default_self
554+
with_cli do |cli|
555+
Dir.mktmpdir do |dir|
556+
(Pathname(dir) + 'a.rbs').write(<<~RBS)
557+
module A[T = self]
558+
end
559+
560+
class B[S = self]
561+
end
562+
563+
interface _C[T = self]
564+
end
565+
RBS
566+
567+
(Pathname(dir) + 'b.rbs').write(<<~RBS)
568+
type t[T = self] = untyped
569+
RBS
570+
571+
cli.run(["-I", dir, "validate"])
572+
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)"
575+
end
576+
end
577+
end
578+
553579
def test_validate_multiple
554580
with_cli do |cli|
555581
Dir.mktmpdir do |dir|

0 commit comments

Comments
 (0)