rbs 1.7.0.beta.4 → 1.7.0.beta.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afd173e37912ce2897a5ff7b9ec6e54bed7258abd7015ac80ae5fa9baa380df5
4
- data.tar.gz: 77b07c52dc592c5f5b01df9d4ab8c91d59942c67f158a8f3386926922e197042
3
+ metadata.gz: 813a7a51e3db502f844756f75a52356945988ffc9e3230b6ff564d7864af02d4
4
+ data.tar.gz: 2589b291bd8fa87c7228d3204d2c6b4541617c450e64da2efc28fa658c92f0bb
5
5
  SHA512:
6
- metadata.gz: e03c35027deec7e866534c1f79fe02060ea5672a3e3e8abe9ac1ae5940f2dd7cd99eeed5ee71d9a5991b3074984a6daaaa58d09c380b0cdcb40c568bae50427d
7
- data.tar.gz: 92a8cc1a171669ca98c5e323293258ff774747712fb24c0b342e28da866077fc10f4c4bbb2699857842ca7bba9829c014c3b69b5e80a1690aa77027f55c7b083
6
+ metadata.gz: 1acea4997b9a4d30da59bb02b0d7bb8afa63794c9102b35efd9627efab007195a60ad3e42ebd1595333cd5965acb1e4d1af576cd23e28efab83da6fed5ee649e
7
+ data.tar.gz: 4822b8fa8cb7fc652d847d90a1bf15215f8229eda1cd11ef9307e03a4abdc0be1ef3a5b117e6fdd00ec7ad43db8cfd914903125dcacea69a8e477b6b2d1cf917
data/CHANGELOG.md CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  ## master
4
4
 
5
- ## 1.7.0 (beta.4)
5
+ ## 1.7.0 (beta.5)
6
6
 
7
7
  ### Signature updates
8
8
 
9
9
  * io/console ([\#783](https://github.com/ruby/rbs/pull/783))
10
10
  * `Net::HTTPRequest` ([\#784](https://github.com/ruby/rbs/pull/784))
11
11
  * `Tempfile.new`, `Tempfile.create` ([\#792](https://github.com/ruby/rbs/pull/792), [\#791](https://github.com/ruby/rbs/pull/791))
12
+ * `#clone` ([#811](https://github.com/ruby/rbs/pull/811))
12
13
 
13
14
  ### Library changes
14
15
 
@@ -16,6 +17,7 @@
16
17
  * Replace RBS::Parser ([#788](https://github.com/ruby/rbs/pull/788), [#789](https://github.com/ruby/rbs/pull/789))
17
18
  * Print deprecation warning ([\#801](https://github.com/ruby/rbs/pull/801))
18
19
  * Make `Parser::KEYWORDS` a hash ([\#804](https://github.com/ruby/rbs/pull/804))
20
+ * Use _partial clone_ for `rbs collection` installer ([#805](https://github.com/ruby/rbs/pull/805))
19
21
 
20
22
  ## 1.6.2 (2021-09-09)
21
23
 
data/core/binding.rbs CHANGED
@@ -31,6 +31,8 @@
31
31
  class Binding
32
32
  public
33
33
 
34
+ def clone: () -> self
35
+
34
36
  # Evaluates the Ruby expression(s) in *string*, in the *binding*'s context. If
35
37
  # the optional *filename* and *lineno* parameters are present, they will be used
36
38
  # when reporting syntax errors.
data/core/complex.rbs CHANGED
@@ -165,8 +165,6 @@ class Complex < Numeric
165
165
 
166
166
  def ceil: (*untyped) -> bot
167
167
 
168
- def clone: (?freeze: bool) -> self
169
-
170
168
  def coerce: (Numeric) -> [ Complex, Complex ]
171
169
 
172
170
  # Returns the complex conjugate.
data/core/float.rbs CHANGED
@@ -171,8 +171,6 @@ class Float < Numeric
171
171
  def ceil: () -> Integer
172
172
  | (int digits) -> (Integer | Float)
173
173
 
174
- def clone: (?freeze: bool) -> self
175
-
176
174
  # Returns an array with both `numeric` and `float` represented as Float objects.
177
175
  #
178
176
  # This is achieved by converting `numeric` to a Float.
data/core/integer.rbs CHANGED
@@ -272,8 +272,6 @@ class Integer < Numeric
272
272
  #
273
273
  def chr: (?encoding) -> String
274
274
 
275
- def clone: (?freeze: bool) -> self
276
-
277
275
  # Returns an array with both a `numeric` and a `big` represented as Bignum
278
276
  # objects.
279
277
  #
data/core/numeric.rbs CHANGED
@@ -416,4 +416,11 @@ class Numeric
416
416
  # Returns `true` if `num` has a zero value.
417
417
  #
418
418
  def zero?: () -> bool
419
+
420
+ # Returns +self+.
421
+ #
422
+ # Raises an exception if the value for +freeze+ is neither +true+ nor +nil+.
423
+ #
424
+ # Related: Numeric#dup.
425
+ def clone: (?freeze: true?) -> self
419
426
  end
data/core/object.rbs CHANGED
@@ -76,7 +76,7 @@ class Object < BasicObject
76
76
  # This method may have class-specific behavior. If so, that behavior will be
77
77
  # documented under the #`initialize_copy` method of the class.
78
78
  #
79
- def clone: (?freeze: bool) -> self
79
+ def clone: (?freeze: bool?) -> self
80
80
 
81
81
  # Defines a singleton method in the receiver. The *method* parameter can be a
82
82
  # `Proc`, a `Method` or an `UnboundMethod` object. If a block is specified, it
data/core/proc.rbs CHANGED
@@ -210,6 +210,8 @@
210
210
  # {test: 1}.to_proc.call(:test) #=> 1
211
211
  # %i[test many keys].map(&{test: 1}) #=> [1, nil, nil]
212
212
  class Proc < Object
213
+ def clone: () -> self
214
+
213
215
  # Returns the number of mandatory arguments. If the block is declared to
214
216
  # take no arguments, returns 0. If the block is known to take exactly n
215
217
  # arguments, returns n. If the block has optional arguments, returns -n-1,
data/core/rational.rbs CHANGED
@@ -175,8 +175,6 @@ class Rational < Numeric
175
175
  def ceil: () -> Integer
176
176
  | (Integer digits) -> (Integer | Rational)
177
177
 
178
- def clone: (?freeze: bool) -> self
179
-
180
178
  def coerce: (Numeric) -> [Numeric, Numeric]
181
179
 
182
180
  def conj: () -> Rational
@@ -45,6 +45,19 @@
45
45
  # um.bind(t).call #=> :original
46
46
  #
47
47
  class UnboundMethod
48
+ # Returns a clone of this method.
49
+ #
50
+ # class A
51
+ # def foo
52
+ # return "bar"
53
+ # end
54
+ # end
55
+ #
56
+ # m = A.new.method(:foo)
57
+ # m.call # => "bar"
58
+ # n = m.clone.call # => "bar"
59
+ def clone: () -> self
60
+
48
61
  # Returns an indication of the number of arguments accepted by a method. Returns
49
62
  # a nonnegative integer for methods that take a fixed number of arguments. For
50
63
  # Ruby methods that take a variable number of arguments, returns -n-1, where n
@@ -229,9 +229,9 @@ end
229
229
 
230
230
  ```ruby
231
231
  # .rb
232
- [1,2,3,4,5].select {|num| num.even? }
232
+ [1,2,3,4,5].filter {|num| num.even? }
233
233
  # => [2, 4]
234
- %w[ a b c d e f ].select {|v| v =~ /[aeiou]/ }
234
+ %w[ a b c d e f ].filter {|v| v =~ /[aeiou]/ }
235
235
  # => ["a", "e"]
236
236
  [1,2,3,4,5].filter
237
237
  ```
data/docs/syntax.md CHANGED
@@ -110,10 +110,10 @@ Array[Integer | String] # Array of Integer or String
110
110
  Intersection type denotes _a type of all of the given types_.
111
111
 
112
112
  ```
113
- Integer & String # Integer and String
113
+ _Reader & _Writer # _Reader and _Writer
114
114
  ```
115
115
 
116
- Note that `&` has higher precedence than `|` that `Integer & String | Symbol` is `(Integer & String) | Symbol`.
116
+ Note that `&` has higher precedence than `|` that `A & B | C` is `(A & B) | C`.
117
117
 
118
118
  ### Optional type
119
119
 
@@ -289,7 +289,6 @@ _method-member_ ::= `def` _method-name_ `:` _method-types_ # Instance
289
289
  | `def self?.` _method-name_ `:` _method-types_ # Singleton and instance method
290
290
 
291
291
  _method-types_ ::= # Empty
292
- | `super` # `super` overloading
293
292
  | _type-parameters_ _method-type_ `|` _method-types_ # Overloading types
294
293
  | `...` # Overloading for duplicate definitions
295
294
 
@@ -1487,6 +1487,8 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
1487
1487
  case INSTANCE_SINGLETON_KIND:
1488
1488
  k = ID2SYM(rb_intern("singleton_instance"));
1489
1489
  break;
1490
+ default:
1491
+ rbs_abort();
1490
1492
  }
1491
1493
 
1492
1494
  VALUE location = rbs_new_location(state->buffer, member_range);
@@ -87,7 +87,6 @@ bool parser_typevar_member(parserstate *state, ID id) {
87
87
  }
88
88
 
89
89
  void print_parser(parserstate *state) {
90
- pp(state->buffer);
91
90
  printf(" current_token = %s (%d...%d)\n", token_type_str(state->current_token.type), state->current_token.range.start.char_pos, state->current_token.range.end.char_pos);
92
91
  printf(" next_token = %s (%d...%d)\n", token_type_str(state->next_token.type), state->next_token.range.start.char_pos, state->next_token.range.end.char_pos);
93
92
  printf(" next_token2 = %s (%d...%d)\n", token_type_str(state->next_token2.type), state->next_token2.range.start.char_pos, state->next_token2.range.end.char_pos);
@@ -37,4 +37,4 @@ VALUE rbs_unquote_string(parserstate *state, range rg, int offset_bytes);
37
37
  * foo.rbs:11:21...11:25: Syntax error: {message}, token=`{tok source}` ({tok type})
38
38
  * ```
39
39
  * */
40
- NORETURN(void) raise_syntax_error(parserstate *state, token tok, const char *fmt, ...);
40
+ PRINTF_ARGS(NORETURN(void) raise_syntax_error(parserstate *state, token tok, const char *fmt, ...), 3, 4);
@@ -41,6 +41,4 @@ VALUE rbs_type_name(VALUE namespace, VALUE name);
41
41
  VALUE rbs_union(VALUE types, VALUE location);
42
42
  VALUE rbs_variable(VALUE name, VALUE location);
43
43
 
44
- void pp(VALUE object);
45
-
46
44
  #endif
@@ -102,7 +102,12 @@ module RBS
102
102
  git 'fetch', 'origin'
103
103
  end
104
104
  else
105
- git 'clone', remote, git_dir.to_s
105
+ begin
106
+ # git v2.27.0 or greater
107
+ git 'clone', '--filter=blob:none', remote, git_dir.to_s
108
+ rescue CommandError
109
+ git 'clone', remote, git_dir.to_s
110
+ end
106
111
  end
107
112
 
108
113
  begin
@@ -0,0 +1,113 @@
1
+ module RBS
2
+ module Prototype
3
+ module Helpers
4
+ private
5
+
6
+ def block_from_body(node)
7
+ _, args_node, body_node = node.children
8
+
9
+ _pre_num, _pre_init, _opt, _first_post, _post_num, _post_init, _rest, _kw, _kwrest, block = args_from_node(args_node)
10
+
11
+ method_block = nil
12
+
13
+ if block
14
+ method_block = Types::Block.new(
15
+ # HACK: The `block` is :& on `def m(...)` syntax.
16
+ # In this case the block looks optional in most cases, so it marks optional.
17
+ # In other cases, we can't determine which is required or optional, so it marks required.
18
+ required: block != :&,
19
+ type: Types::Function.empty(untyped)
20
+ )
21
+ end
22
+
23
+ if body_node
24
+ if (yields = any_node?(body_node) {|n| n.type == :YIELD })
25
+ method_block = Types::Block.new(
26
+ required: true,
27
+ type: Types::Function.empty(untyped)
28
+ )
29
+
30
+ yields.each do |yield_node|
31
+ array_content = yield_node.children[0]&.children&.compact || []
32
+
33
+ positionals, keywords = if keyword_hash?(array_content.last)
34
+ [array_content.take(array_content.size - 1), array_content.last]
35
+ else
36
+ [array_content, nil]
37
+ end
38
+
39
+ if (diff = positionals.size - method_block.type.required_positionals.size) > 0
40
+ diff.times do
41
+ method_block.type.required_positionals << Types::Function::Param.new(
42
+ type: untyped,
43
+ name: nil
44
+ )
45
+ end
46
+ end
47
+
48
+ if keywords
49
+ keywords.children[0].children.each_slice(2) do |key_node, value_node|
50
+ if key_node
51
+ key = key_node.children[0]
52
+ method_block.type.required_keywords[key] ||=
53
+ Types::Function::Param.new(
54
+ type: untyped,
55
+ name: nil
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ method_block
65
+ end
66
+
67
+ def each_child(node, &block)
68
+ each_node node.children, &block
69
+ end
70
+
71
+ def each_node(nodes)
72
+ nodes.each do |child|
73
+ if child.is_a?(RubyVM::AbstractSyntaxTree::Node)
74
+ yield child
75
+ end
76
+ end
77
+ end
78
+
79
+
80
+ def any_node?(node, nodes: [], &block)
81
+ if yield(node)
82
+ nodes << node
83
+ end
84
+
85
+ each_child node do |child|
86
+ any_node? child, nodes: nodes, &block
87
+ end
88
+
89
+ nodes.empty? ? nil : nodes
90
+ end
91
+
92
+ def keyword_hash?(node)
93
+ if node
94
+ if node.type == :HASH
95
+ node.children[0].children.compact.each_slice(2).all? {|key, _|
96
+ key.type == :LIT && key.children[0].is_a?(Symbol)
97
+ }
98
+ end
99
+ end
100
+ end
101
+
102
+ # NOTE: args_node may be a nil by a bug
103
+ # https://bugs.ruby-lang.org/issues/17495
104
+ def args_from_node(args_node)
105
+ args_node&.children || [0, nil, nil, nil, 0, nil, nil, nil, nil, nil]
106
+ end
107
+
108
+ def untyped
109
+ @untyped ||= Types::Bases::Any.new(location: nil)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -1,6 +1,8 @@
1
1
  module RBS
2
2
  module Prototype
3
3
  class RB
4
+ include Helpers
5
+
4
6
  Context = Struct.new(:module_function, :singleton, :namespace, keyword_init: true) do
5
7
  def self.initial(namespace: Namespace.root)
6
8
  self.new(module_function: false, singleton: false, namespace: namespace)
@@ -372,18 +374,6 @@ module RBS
372
374
  end
373
375
  end
374
376
 
375
- def each_node(nodes)
376
- nodes.each do |child|
377
- if child.is_a?(RubyVM::AbstractSyntaxTree::Node)
378
- yield child
379
- end
380
- end
381
- end
382
-
383
- def each_child(node, &block)
384
- each_node node.children, &block
385
- end
386
-
387
377
  def function_type_from_body(node, def_name)
388
378
  table_node, args_node, *_ = node.children
389
379
 
@@ -568,95 +558,6 @@ module RBS
568
558
  end
569
559
  end
570
560
 
571
- def block_from_body(node)
572
- _, args_node, body_node = node.children
573
-
574
- _pre_num, _pre_init, _opt, _first_post, _post_num, _post_init, _rest, _kw, _kwrest, block = args_from_node(args_node)
575
-
576
- method_block = nil
577
-
578
- if block
579
- method_block = Types::Block.new(
580
- # HACK: The `block` is :& on `def m(...)` syntax.
581
- # In this case the block looks optional in most cases, so it marks optional.
582
- # In other cases, we can't determine which is required or optional, so it marks required.
583
- required: block != :&,
584
- type: Types::Function.empty(untyped)
585
- )
586
- end
587
-
588
- if body_node
589
- if (yields = any_node?(body_node) {|n| n.type == :YIELD })
590
- method_block = Types::Block.new(
591
- required: true,
592
- type: Types::Function.empty(untyped)
593
- )
594
-
595
- yields.each do |yield_node|
596
- array_content = yield_node.children[0]&.children&.compact || []
597
-
598
- positionals, keywords = if keyword_hash?(array_content.last)
599
- [array_content.take(array_content.size - 1), array_content.last]
600
- else
601
- [array_content, nil]
602
- end
603
-
604
- if (diff = positionals.size - method_block.type.required_positionals.size) > 0
605
- diff.times do
606
- method_block.type.required_positionals << Types::Function::Param.new(
607
- type: untyped,
608
- name: nil
609
- )
610
- end
611
- end
612
-
613
- if keywords
614
- keywords.children[0].children.each_slice(2) do |key_node, value_node|
615
- if key_node
616
- key = key_node.children[0]
617
- method_block.type.required_keywords[key] ||=
618
- Types::Function::Param.new(
619
- type: untyped,
620
- name: nil
621
- )
622
- end
623
- end
624
- end
625
- end
626
- end
627
- end
628
-
629
- method_block
630
- end
631
-
632
- # NOTE: args_node may be a nil by a bug
633
- # https://bugs.ruby-lang.org/issues/17495
634
- def args_from_node(args_node)
635
- args_node&.children || [0, nil, nil, nil, 0, nil, nil, nil, nil, nil]
636
- end
637
-
638
- def keyword_hash?(node)
639
- if node
640
- if node.type == :HASH
641
- node.children[0].children.compact.each_slice(2).all? {|key, _|
642
- key.type == :LIT && key.children[0].is_a?(Symbol)
643
- }
644
- end
645
- end
646
- end
647
-
648
- def any_node?(node, nodes: [], &block)
649
- if yield(node)
650
- nodes << node
651
- end
652
-
653
- each_child node do |child|
654
- any_node? child, nodes: nodes, &block
655
- end
656
-
657
- nodes.empty? ? nil : nodes
658
- end
659
-
660
561
  def node_type(node, default: Types::Bases::Any.new(location: nil))
661
562
  case node.type
662
563
  when :LIT
@@ -689,10 +590,6 @@ module RBS
689
590
  end
690
591
  end
691
592
 
692
- def untyped
693
- @untyped ||= Types::Bases::Any.new(location: nil)
694
- end
695
-
696
593
  def private
697
594
  @private ||= AST::Members::Private.new(location: nil)
698
595
  end
@@ -1,6 +1,8 @@
1
1
  module RBS
2
2
  module Prototype
3
3
  class Runtime
4
+ include Helpers
5
+
4
6
  attr_reader :patterns
5
7
  attr_reader :env
6
8
  attr_reader :merge
@@ -138,6 +140,8 @@ module RBS
138
140
  end
139
141
  end
140
142
 
143
+ block ||= block_from_ast_of(method)
144
+
141
145
  return_type = if method.name == :initialize
142
146
  Types::Bases::Void.new(location: nil)
143
147
  else
@@ -522,6 +526,18 @@ module RBS
522
526
  []
523
527
  end
524
528
  end
529
+
530
+ def block_from_ast_of(method)
531
+ return nil if RUBY_VERSION < '3.1'
532
+
533
+ begin
534
+ ast = RubyVM::AbstractSyntaxTree.of(method)
535
+ rescue ArgumentError
536
+ return # When the method is defined in eval
537
+ end
538
+
539
+ block_from_body(ast) if ast&.type == :SCOPE
540
+ end
525
541
  end
526
542
  end
527
543
  end
data/lib/rbs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RBS
2
- VERSION = "1.7.0.beta.4"
2
+ VERSION = "1.7.0.beta.5"
3
3
  end
data/lib/rbs.rb CHANGED
@@ -32,6 +32,7 @@ require "rbs/constant"
32
32
  require "rbs/constant_table"
33
33
  require "rbs/ast/comment"
34
34
  require "rbs/writer"
35
+ require "rbs/prototype/helpers"
35
36
  require "rbs/prototype/rbi"
36
37
  require "rbs/prototype/rb"
37
38
  require "rbs/prototype/runtime"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0.beta.4
4
+ version: 1.7.0.beta.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-22 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.
@@ -158,6 +158,7 @@ files:
158
158
  - lib/rbs/parser_compat/located_value.rb
159
159
  - lib/rbs/parser_compat/semantics_error.rb
160
160
  - lib/rbs/parser_compat/syntax_error.rb
161
+ - lib/rbs/prototype/helpers.rb
161
162
  - lib/rbs/prototype/rb.rb
162
163
  - lib/rbs/prototype/rbi.rb
163
164
  - lib/rbs/prototype/runtime.rb