Skip to content

Commit 122d484

Browse files
committed
Merge remote-tracking branch 'origin/master' into chomp
2 parents 74c7a7b + a7178b1 commit 122d484

File tree

25 files changed

+412
-309
lines changed

25 files changed

+412
-309
lines changed

.github/workflows/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
1515
steps:
1616
- name: Dependabot metadata
17-
uses: dependabot/fetch-metadata@dbb049abf0d677abbd7f7eee0375145b417fdd34 # v2.2.0
17+
uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7 # v2.3.0
1818
id: metadata
1919
- name: Checkout repository
2020
uses: actions/checkout@v4

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ group :libs do
2929
gem "dbm"
3030
gem "mutex_m"
3131
gem "nkf"
32+
gem "pathname"
3233
end
3334

3435
group :profilers do

Gemfile.lock

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ GEM
5252
json-schema (5.1.1)
5353
addressable (~> 2.8)
5454
bigdecimal (~> 3.1)
55-
language_server-protocol (3.17.0.3)
55+
language_server-protocol (3.17.0.4)
5656
listen (3.9.0)
5757
rb-fsevent (~> 0.10, >= 0.10.3)
5858
rb-inotify (~> 0.9, >= 0.9.10)
@@ -71,6 +71,7 @@ GEM
7171
parser (3.3.7.0)
7272
ast (~> 2.4.1)
7373
racc
74+
pathname (0.4.0)
7475
power_assert (2.0.5)
7576
pstore (0.1.4)
7677
psych (4.0.6)
@@ -113,7 +114,7 @@ GEM
113114
rubocop-ast (>= 1.36.2, < 2.0)
114115
ruby-progressbar (~> 1.7)
115116
unicode-display_width (>= 2.4.0, < 4.0)
116-
rubocop-ast (1.37.0)
117+
rubocop-ast (1.38.0)
117118
parser (>= 3.3.1.0)
118119
rubocop-on-rbs (1.3.0)
119120
rbs (~> 3.5)
@@ -177,6 +178,7 @@ DEPENDENCIES
177178
net-smtp
178179
nkf
179180
ostruct
181+
pathname
180182
pstore
181183
raap
182184
rake

config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ nodes:
191191
- name: variance
192192
- name: upper_bound
193193
- name: default_type
194+
- name: unchecked
194195
- name: location
195196
- name: RBS::MethodType
196197
fields:
@@ -213,6 +214,7 @@ nodes:
213214
- name: location
214215
- name: RBS::Types::Bases::Any
215216
fields:
217+
- name: todo
216218
- name: location
217219
- name: RBS::Types::Bases::Bool
218220
fields:

core/gc.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module GC
111111
# `:HAVE_FINALIZE`
112112
# :
113113
#
114-
def self.raw_data: () -> Array[Hash[Symbol, untyped]]
114+
def self.raw_data: () -> Array[Hash[Symbol, untyped]]?
115115

116116
# <!--
117117
# rdoc-file=gc.c

docs/syntax.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ The following `class`/`instance` types are allowed.
289289
class Foo
290290
attr_reader parent: class
291291
292-
def foo: () -> instance
292+
def foo: () -> instance # behaves like `self` in this context
293+
294+
def self?.bar: () -> instance # behaves like `class` for `def self.bar()` and `self` for `def bar()`
293295
294296
@@foos: Array[instance]
295297

ext/rbs_extension/parser.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -993,12 +993,10 @@ static VALUE parse_simple(parserstate *state) {
993993
return rbs_bases_void(rbs_location_current_token(state));
994994
}
995995
case kUNTYPED: {
996-
return rbs_bases_any(rbs_location_current_token(state));
996+
return rbs_bases_any(false, rbs_location_current_token(state));
997997
}
998998
case k__TODO__: {
999-
VALUE type = rbs_bases_any(rbs_location_current_token(state));
1000-
rb_funcall(type, rb_intern("todo!"), 0);
1001-
return type;
999+
return rbs_bases_any(true, rbs_location_current_token(state));
10021000
}
10031001
case tINTEGER: {
10041002
VALUE literal = rb_funcall(
@@ -1158,7 +1156,7 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
11581156
rg->start = state->current_token.range.start;
11591157

11601158
while (true) {
1161-
bool unchecked = false;
1159+
VALUE unchecked = Qfalse;
11621160
VALUE variance = ID2SYM(rb_intern("invariant"));
11631161
VALUE upper_bound = Qnil;
11641162
VALUE default_type = Qnil;
@@ -1170,7 +1168,7 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
11701168
range unchecked_range = NULL_RANGE;
11711169
if (module_type_params) {
11721170
if (state->next_token.type == kUNCHECKED) {
1173-
unchecked = true;
1171+
unchecked = Qtrue;
11741172
parser_advance(state);
11751173
unchecked_range = state->current_token.range;
11761174
}
@@ -1245,11 +1243,7 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
12451243
rbs_loc_add_optional_child(loc, INTERN("upper_bound"), upper_bound_range);
12461244
rbs_loc_add_optional_child(loc, INTERN("default"), default_type_range);
12471245

1248-
VALUE param = rbs_ast_type_param(name, variance, upper_bound, default_type, location);
1249-
1250-
if (unchecked) {
1251-
rb_funcall(param, rb_intern("unchecked!"), 0);
1252-
}
1246+
VALUE param = rbs_ast_type_param(name, variance, upper_bound, default_type, unchecked, location);
12531247

12541248
melt_array(&params);
12551249
rb_ary_push(params, param);

include/rbs/ruby_objs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method
3939
VALUE rbs_ast_members_prepend(VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
4040
VALUE rbs_ast_members_private(VALUE location);
4141
VALUE rbs_ast_members_public(VALUE location);
42-
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE location);
42+
VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE unchecked, VALUE location);
4343
VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location);
4444
VALUE rbs_namespace(VALUE path, VALUE absolute);
4545
VALUE rbs_type_name(VALUE namespace, VALUE name);
4646
VALUE rbs_alias(VALUE name, VALUE args, VALUE location);
47-
VALUE rbs_bases_any(VALUE location);
47+
VALUE rbs_bases_any(VALUE todo, VALUE location);
4848
VALUE rbs_bases_bool(VALUE location);
4949
VALUE rbs_bases_bottom(VALUE location);
5050
VALUE rbs_bases_class(VALUE location);

lib/rbs/ast/type_param.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ module AST
55
class TypeParam
66
attr_reader :name, :variance, :location, :upper_bound_type, :default_type
77

8-
def initialize(name:, variance:, upper_bound:, location:, default_type: nil)
8+
def initialize(name:, variance:, upper_bound:, location:, default_type: nil, unchecked: false)
99
@name = name
1010
@variance = variance
1111
@upper_bound_type = upper_bound
1212
@location = location
13-
@unchecked = false
1413
@default_type = default_type
14+
@unchecked = unchecked
1515
end
1616

1717
def upper_bound

lib/rbs/test/type_check.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def initialize(self_class:, builder:, sample_size:, unchecked_classes:, instance
2222
end
2323

2424
def overloaded_call(method, method_name, call, errors:)
25-
es = method.method_types.map do |method_type|
26-
es = method_call(method_name, method_type, call, errors: [])
25+
es = method.defs.map do |type_def|
26+
es = method_call(method_name, type_def.type, call, errors: [], annotations: type_def.annotations)
2727

2828
if es.empty?
2929
return errors
@@ -58,11 +58,11 @@ def overloaded_call(method, method_name, call, errors:)
5858
errors
5959
end
6060

61-
def method_call(method_name, method_type, call, errors:)
61+
def method_call(method_name, method_type, call, errors:, annotations: [])
6262
return errors if method_type.type.is_a?(Types::UntypedFunction)
6363

6464
args(method_name, method_type, method_type.type, call.method_call, errors, type_error: Errors::ArgumentTypeError, argument_error: Errors::ArgumentError)
65-
self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError)
65+
self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError, annotations:)
6666

6767
if method_type.block
6868
case
@@ -106,8 +106,10 @@ def args(method_name, method_type, fun, call, errors, type_error:, argument_erro
106106
end
107107
end
108108

109-
def return(method_name, method_type, fun, call, errors, return_error:)
109+
def return(method_name, method_type, fun, call, errors, return_error:, annotations: [])
110110
if call.return?
111+
return if Test.call(call.return_value, IS_AP, NilClass) && annotations.find { |a| a.string == "implicitly-returns-nil" }
112+
111113
unless value(call.return_value, fun.return_type)
112114
errors << return_error.new(klass: self_class,
113115
method_name: method_name,

0 commit comments

Comments
 (0)