Skip to content

Commit 40fcae4

Browse files
authored
Merge branch 'master' into Fix_UNIXSocket_send_io_and_recv_io_types
2 parents 5b8ccd8 + 831a7db commit 40fcae4

File tree

11 files changed

+213
-11
lines changed

11 files changed

+213
-11
lines changed

.github/workflows/windows.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ jobs:
2727
run: |
2828
ruby -e '
2929
exit if "${{ matrix.ruby }}" != "ucrt" && "${{ matrix.ruby }}" != "mswin"
30-
bundled_gems = Dir.glob("D:/ruby-${{ matrix.ruby }}/lib/ruby/gems/*/cache/*.gem")
31-
.map { |path| File.basename(path, ".gem")[/^(.+)-[^-]+$/, 1] }
30+
31+
require "open-uri"
32+
require "json"
33+
34+
res = URI.parse("https://stdgems.org/bundled_gems.json").read
35+
bundled_gems = JSON.parse(res)["gems"].map{_1["gem"]}
3236
system "gem uninstall #{bundled_gems.join(" ")}", exception: true
3337
'
3438
- name: bundle install

Gemfile.lock

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,23 @@ GEM
5353
addressable (~> 2.8)
5454
bigdecimal (~> 3.1)
5555
language_server-protocol (3.17.0.4)
56+
lint_roller (1.1.0)
5657
listen (3.9.0)
5758
rb-fsevent (~> 0.10, >= 0.10.3)
5859
rb-inotify (~> 0.9, >= 0.9.10)
59-
logger (1.6.5)
60+
logger (1.6.6)
6061
marcel (1.0.4)
6162
memory_profiler (1.1.0)
6263
minitest (5.25.4)
6364
mutex_m (0.3.0)
6465
net-protocol (0.2.2)
6566
timeout
66-
net-smtp (0.5.0)
67+
net-smtp (0.5.1)
6768
net-protocol
6869
nkf (0.2.0)
6970
ostruct (0.6.1)
7071
parallel (1.26.3)
71-
parser (3.3.7.0)
72+
parser (3.3.7.1)
7273
ast (~> 2.4.1)
7374
racc
7475
pathname (0.4.0)
@@ -77,7 +78,7 @@ GEM
7778
psych (4.0.6)
7879
stringio
7980
public_suffix (6.0.1)
80-
raap (1.1.0)
81+
raap (1.2.0)
8182
rbs (~> 3.0)
8283
timeout (~> 0.4)
8384
racc (1.8.1)
@@ -104,14 +105,15 @@ GEM
104105
diff-lcs (>= 1.2.0, < 2.0)
105106
rspec-support (~> 3.13.0)
106107
rspec-support (3.13.2)
107-
rubocop (1.71.0)
108+
rubocop (1.72.2)
108109
json (~> 2.3)
109-
language_server-protocol (>= 3.17.0)
110+
language_server-protocol (~> 3.17.0.2)
111+
lint_roller (~> 1.1.0)
110112
parallel (~> 1.10)
111113
parser (>= 3.3.0.2)
112114
rainbow (>= 2.2.2, < 4.0)
113115
regexp_parser (>= 2.9.3, < 3.0)
114-
rubocop-ast (>= 1.36.2, < 2.0)
116+
rubocop-ast (>= 1.38.0, < 2.0)
115117
ruby-progressbar (~> 1.7)
116118
unicode-display_width (>= 2.4.0, < 4.0)
117119
rubocop-ast (1.38.0)

lib/rbs/cli/validate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def validate_class_module_definition
196196
end
197197
InvalidTypeApplicationError.check!(type_name: member.name, params: params, args: member.args, location: member.location)
198198
when AST::Members::Var
199+
@validator.validate_variable(member)
199200
void_type_context_validator(member.type)
200201
if member.is_a?(AST::Members::ClassVariable)
201202
no_self_type_validator(member.type)

lib/rbs/definition_builder.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def define_instance(definition, type_name, subst)
151151
end
152152

153153
when AST::Members::InstanceVariable
154+
InstanceVariableDuplicationError.check!(variables: definition.instance_variables, member: member, type_name: type_name)
154155
insert_variable(
155156
type_name,
156157
definition.instance_variables,
@@ -159,6 +160,7 @@ def define_instance(definition, type_name, subst)
159160
)
160161

161162
when AST::Members::ClassVariable
163+
ClassVariableDuplicationError.check!(variables: definition.class_variables, member: member, type_name: type_name)
162164
insert_variable(type_name, definition.class_variables, name: member.name, type: member.type)
163165
end
164166
end
@@ -287,9 +289,11 @@ def build_singleton0(type_name)
287289
end
288290

289291
when AST::Members::ClassInstanceVariable
292+
ClassInstanceVariableDuplicationError.check!(variables: definition.instance_variables, member: member, type_name: type_name)
290293
insert_variable(type_name, definition.instance_variables, name: member.name, type: member.type)
291294

292295
when AST::Members::ClassVariable
296+
ClassVariableDuplicationError.check!(variables: definition.class_variables, member: member, type_name: type_name)
293297
insert_variable(type_name, definition.class_variables, name: member.name, type: member.type)
294298
end
295299
end

lib/rbs/errors.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,51 @@ def type_name
322322
end
323323
end
324324

325+
class VariableDuplicationError < DefinitionError
326+
include DetailedMessageable
327+
328+
attr_reader :member
329+
330+
def initialize(member:)
331+
@member = member
332+
333+
super "#{Location.to_string location}: Duplicated variable name #{member.name}"
334+
end
335+
336+
def location
337+
loc = @member.location or raise
338+
loc[:name]
339+
end
340+
end
341+
342+
class InstanceVariableDuplicationError < VariableDuplicationError
343+
def self.check!(variables:, member:, type_name:)
344+
if old = variables[member.name]
345+
if old.declared_in == type_name
346+
raise new(member: member)
347+
end
348+
end
349+
end
350+
end
351+
352+
class ClassInstanceVariableDuplicationError < VariableDuplicationError
353+
def self.check!(variables:, member:, type_name:)
354+
if old = variables[member.name]
355+
if old.declared_in == type_name
356+
raise new(member: member)
357+
end
358+
end
359+
end
360+
end
361+
362+
class ClassVariableDuplicationError < VariableDuplicationError
363+
def self.check!(variables:, member:, type_name:)
364+
if old = variables[member.name]
365+
raise new(member: member)
366+
end
367+
end
368+
end
369+
325370
class UnknownMethodAliasError < DefinitionError
326371
include DetailedMessageable
327372

lib/rbs/validator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ def validate_type_params(params, type_name: , method_name: nil, location:)
151151
end
152152
end
153153

154+
def validate_variable(var)
155+
validate_type(var.type, context: nil)
156+
end
157+
154158
def validate_class_alias(entry:)
155159
case env.normalize_module_name?(entry.decl.new_name)
156160
when nil

sig/errors.rbs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,28 @@ module RBS
182182
def location: () -> AST::Members::Mixin::loc?
183183
end
184184

185+
class VariableDuplicationError < DefinitionError
186+
include DetailedMessageable
187+
188+
attr_reader member: AST::Members::Var
189+
190+
def initialize: (member: AST::Members::Var) -> void
191+
192+
def location: () -> Location[bot, bot]
193+
end
194+
195+
class InstanceVariableDuplicationError < VariableDuplicationError
196+
def self.check!: (variables: Hash[Symbol, Definition::Variable], member: AST::Members::InstanceVariable, type_name: TypeName) -> void
197+
end
198+
199+
class ClassInstanceVariableDuplicationError < VariableDuplicationError
200+
def self.check!: (variables: Hash[Symbol, Definition::Variable], member: AST::Members::ClassInstanceVariable, type_name: TypeName) -> void
201+
end
202+
203+
class ClassVariableDuplicationError < VariableDuplicationError
204+
def self.check!: (variables: Hash[Symbol, Definition::Variable], member: AST::Members::ClassVariable, type_name: TypeName) -> void
205+
end
206+
185207
# The `alias` member declares an alias from unknown method
186208
#
187209
class UnknownMethodAliasError < DefinitionError

sig/validator.rbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ module RBS
4949
#
5050
def validate_class_alias: (entry: Environment::ClassAliasEntry | Environment::ModuleAliasEntry) -> void
5151

52+
# Validates instance/class-instance/class variables.
53+
#
54+
def validate_variable: (AST::Members::Var) -> void
55+
5256
private
5357

5458
# Resolves relative type names to absolute type names in given context.

steep/Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ GEM
2626
fileutils (1.7.3)
2727
i18n (1.14.7)
2828
concurrent-ruby (~> 1.0)
29-
json (2.9.1)
29+
json (2.10.1)
3030
language_server-protocol (3.17.0.4)
3131
listen (3.9.0)
3232
rb-fsevent (~> 0.10, >= 0.10.3)
3333
rb-inotify (~> 0.9, >= 0.9.10)
3434
logger (1.6.5)
3535
minitest (5.25.4)
36-
parser (3.3.7.0)
36+
parser (3.3.7.1)
3737
ast (~> 2.4.1)
3838
racc
3939
racc (1.8.1)

test/rbs/definition_builder_test.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,4 +2705,64 @@ module Foo
27052705
end
27062706
end
27072707
end
2708+
2709+
def test_duplicated_variable
2710+
SignatureManager.new do |manager|
2711+
manager.add_file("instance.rbs", <<-EOF)
2712+
class InstanceVariable
2713+
@instance: Integer
2714+
@instance: Integer
2715+
end
2716+
2717+
class ClassInstanceVariable
2718+
self.@class_instance: Integer
2719+
self.@class_instance: Integer
2720+
end
2721+
2722+
class ClassVariable
2723+
@@class: Integer
2724+
@@class: Integer
2725+
end
2726+
EOF
2727+
2728+
manager.build do |env|
2729+
builder = DefinitionBuilder.new(env: env)
2730+
2731+
assert_raises(RBS::InstanceVariableDuplicationError) do
2732+
builder.build_instance(type_name("::InstanceVariable"))
2733+
end
2734+
assert_raises(RBS::ClassInstanceVariableDuplicationError) do
2735+
builder.build_singleton(type_name("::ClassInstanceVariable"))
2736+
end
2737+
assert_raises(RBS::ClassVariableDuplicationError) do
2738+
builder.build_instance(type_name("::ClassVariable"))
2739+
end
2740+
end
2741+
end
2742+
2743+
SignatureManager.new do |manager|
2744+
manager.add_file("inherited.rbs", <<-EOF)
2745+
class A
2746+
@instance: Integer
2747+
self.@class_instance: Integer
2748+
@@class: Integer
2749+
end
2750+
2751+
class B < A
2752+
@instance: Integer
2753+
self.@class_instance: Integer
2754+
@@class: Integer
2755+
end
2756+
EOF
2757+
2758+
manager.build do |env|
2759+
builder = DefinitionBuilder.new(env: env)
2760+
2761+
builder.build_instance(type_name("::A"))
2762+
assert_raises(RBS::ClassVariableDuplicationError) do
2763+
builder.build_instance(type_name("::B"))
2764+
end
2765+
end
2766+
end
2767+
end
27082768
end

0 commit comments

Comments
 (0)