steep 0.8.2 → 0.9.0

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: b701d322a3c49aa1444c839bee4a2da7265776463f8963780431251ab3c96903
4
- data.tar.gz: '069769e987f34a131983c2c3de966bb0f0591478bf4fa1dd79c3831213bed411'
3
+ metadata.gz: 05a765d5cdc7792406c32f581e041ee9e47b41c1b70dfb0d43e8db5400fbe172
4
+ data.tar.gz: 71e35e1516a261d82082e1278774ff0a8d36c5ffecdd8511ba8de312b93a16f8
5
5
  SHA512:
6
- metadata.gz: f264922829daa436adcf0e0e18bca9cc22397928fed215005785b2e8e3142e51afdd04b4f3b819b89565d1fb4c19cab2d17087445b8f3b313299810d24554646
7
- data.tar.gz: f2b6c543d8f0742b6a971a3040431162c4333e2c0db969b5de7f5e495e86c1a19378fe8b8438255ec1cc4f413a6b21dbe07a7e1acc40d7b3c71e212309093a70
6
+ metadata.gz: b721b3ac5bb01d3296071025ef72a7e2ab76f4900bdfb0909ee8a715642d371812185c4adc74585344a156c43af742e0e35782b8dc9f89966da6d558e7f87f83
7
+ data.tar.gz: 3849077a1ea0d7109eb3b148be3dc2e8260f9cc63df17cb1864235fa2137faa984947a64d95343524c1b34d75fcf4ff9ada215488e15977bcc657359da3cac4c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.8.3 (2018-11-11)
6
+
7
+ * Private methods (#72)
8
+ * `__skip__` to skip type checking (#73)
9
+ * Add `alias` for method types (#75)
10
+ * Fix `Names::Base#hash` (#69 @hanachin)
11
+ * Add `super` in method types (#76)
12
+
5
13
  ## 0.8.2 (2018-11-09)
6
14
 
7
15
  * Fix ElseOnExhaustiveCase error implementation
@@ -113,6 +113,14 @@ module Steep
113
113
  @block = block
114
114
  @return_type = return_type
115
115
  end
116
+
117
+ class Super
118
+ attr_reader :location
119
+
120
+ def initialize(location:)
121
+ @location = location
122
+ end
123
+ end
116
124
  end
117
125
  end
118
126
  end
@@ -56,7 +56,7 @@ module Steep
56
56
  alias eql? ==
57
57
 
58
58
  def hash
59
- self.class.hath ^ path.hash ^ absolute?.hash
59
+ self.class.hash ^ path.hash ^ absolute?.hash
60
60
  end
61
61
 
62
62
  def to_s
@@ -56,6 +56,10 @@ module Steep
56
56
  def incompatible?
57
57
  attributes.include?(:incompatible)
58
58
  end
59
+
60
+ def private?
61
+ attributes.include?(:private)
62
+ end
59
63
  end
60
64
 
61
65
  class Ivar
@@ -93,6 +97,18 @@ module Steep
93
97
  kind == :accessor
94
98
  end
95
99
  end
100
+
101
+ class MethodAlias
102
+ attr_reader :location
103
+ attr_reader :new_name
104
+ attr_reader :original_name
105
+
106
+ def initialize(location:, new_name:, original_name:)
107
+ @location = location
108
+ @new_name = new_name
109
+ @original_name = original_name
110
+ end
111
+ end
96
112
  end
97
113
  end
98
114
  end
@@ -34,7 +34,7 @@ module Steep
34
34
 
35
35
  when AST::Signature::Module
36
36
  yield_self do
37
- instance_interface = builder.build_instance(sig.name, with_initialize: true)
37
+ instance_interface = builder.build_instance(sig.name)
38
38
  instance_args = instance_interface.params.map {|var| AST::Types::Var.fresh(var) }
39
39
 
40
40
  module_interface = builder.build_module(sig.name)
@@ -58,7 +58,7 @@ module Steep
58
58
 
59
59
  when AST::Signature::Class
60
60
  yield_self do
61
- instance_interface = builder.build_instance(sig.name, with_initialize: true)
61
+ instance_interface = builder.build_instance(sig.name)
62
62
  instance_args = instance_interface.params.map {|var| AST::Types::Var.fresh(var) }
63
63
 
64
64
  module_interface = builder.build_class(sig.name, constructor: true)
@@ -39,6 +39,30 @@ module Steep
39
39
  ivar_chains: ivar_chains.transform_values {|chain| chain.subst(subst) }
40
40
  )
41
41
  end
42
+
43
+ def without_private(option)
44
+ if option
45
+ self.class.new(
46
+ name: name,
47
+ params: params,
48
+ methods: methods.reject {|_, method| method.private? },
49
+ supers: supers,
50
+ ivar_chains: ivar_chains
51
+ )
52
+ else
53
+ self
54
+ end
55
+ end
56
+
57
+ def without_initialize
58
+ self.class.new(
59
+ name: name,
60
+ params: params,
61
+ methods: methods.reject {|_, method| method.name == :initialize },
62
+ supers: supers,
63
+ ivar_chains: ivar_chains
64
+ )
65
+ end
42
66
  end
43
67
  end
44
68
  end
@@ -132,11 +132,11 @@ module Steep
132
132
  end
133
133
  end
134
134
 
135
- def build_instance(module_name, with_initialize:)
135
+ def build_instance(module_name)
136
136
  assert_absolute_name! module_name
137
137
  signature = signatures.find_class_or_module(module_name, current_module: AST::Namespace.root)
138
- cache_interface(instance_cache, key: [signature.name, with_initialize]) do
139
- instance_to_interface(signature, with_initialize: with_initialize)
138
+ cache_interface(instance_cache, key: signature.name) do
139
+ instance_to_interface(signature)
140
140
  end
141
141
  end
142
142
 
@@ -173,8 +173,18 @@ module Steep
173
173
  new_method = Method.new(
174
174
  type_name: type_name,
175
175
  name: method.name,
176
- types: method.types.map do |method_type|
177
- method_type_to_method_type(method_type, current: current)
176
+ types: method.types.flat_map do |method_type|
177
+ case method_type
178
+ when AST::MethodType
179
+ [method_type_to_method_type(method_type, current: current)]
180
+ when AST::MethodType::Super
181
+ if super_method
182
+ super_method.types
183
+ else
184
+ Steep.logger.error "`super` specified in method type, but cannot find super method of `#{method.name}` in `#{type_name}` (#{method.location.name || "-"}:#{method.location})"
185
+ []
186
+ end
187
+ end
178
188
  end,
179
189
  super_method: super_method,
180
190
  attributes: method.attributes + extra_attributes
@@ -209,7 +219,7 @@ module Steep
209
219
  )
210
220
  }
211
221
 
212
- klass = build_instance(AST::Builtin::Class.module_name, with_initialize: false)
222
+ klass = build_instance(AST::Builtin::Class.module_name)
213
223
  instantiated = klass.instantiate(
214
224
  type: AST::Types::Self.new,
215
225
  args: [],
@@ -238,7 +248,7 @@ module Steep
238
248
  end
239
249
  when AST::Signature::Members::Extend
240
250
  member_name = signatures.find_module(member.name, current_module: namespace).name
241
- build_instance(member_name, with_initialize: false).yield_self do |module_interface|
251
+ build_instance(member_name).yield_self do |module_interface|
242
252
  merge_mixin(module_interface,
243
253
  member.args.map {|type| absolute_type(type, current: namespace) },
244
254
  methods: methods,
@@ -318,7 +328,7 @@ module Steep
318
328
  methods = {}
319
329
  ivar_chains = {}
320
330
 
321
- module_instance = build_instance(AST::Builtin::Module.module_name, with_initialize: false)
331
+ module_instance = build_instance(AST::Builtin::Module.module_name)
322
332
  instantiated = module_instance.instantiate(
323
333
  type: AST::Types::Self.new,
324
334
  args: [],
@@ -341,7 +351,7 @@ module Steep
341
351
  end
342
352
  when AST::Signature::Members::Extend
343
353
  member_name = signatures.find_module(member.name, current_module: namespace).name
344
- build_instance(member_name, with_initialize: false).yield_self do |module_interface|
354
+ build_instance(member_name).yield_self do |module_interface|
345
355
  merge_mixin(module_interface,
346
356
  member.args.map {|type| absolute_type(type, current: namespace) },
347
357
  methods: methods,
@@ -387,7 +397,7 @@ module Steep
387
397
  )
388
398
  end
389
399
 
390
- def instance_to_interface(sig, with_initialize:)
400
+ def instance_to_interface(sig)
391
401
  module_name = sig.name
392
402
  namespace = module_name.namespace.append(module_name.name)
393
403
 
@@ -402,8 +412,7 @@ module Steep
402
412
  if super_class_name.relative?
403
413
  super_class_name = signatures.find_class(super_class_name, current_module: namespace).name
404
414
  end
405
- super_class_interface = build_instance(super_class_name,
406
- with_initialize: with_initialize)
415
+ super_class_interface = build_instance(super_class_name)
407
416
 
408
417
  supers.push(*super_class_interface.supers)
409
418
  instantiated = super_class_interface.instantiate(
@@ -428,7 +437,7 @@ module Steep
428
437
  case member
429
438
  when AST::Signature::Members::Include
430
439
  member_name = signatures.find_module(member.name, current_module: namespace).name
431
- build_instance(member_name, with_initialize: false).yield_self do |module_interface|
440
+ build_instance(member_name).yield_self do |module_interface|
432
441
  merge_mixin(module_interface,
433
442
  member.args.map {|type| absolute_type(type, current: namespace) },
434
443
  methods: methods,
@@ -443,10 +452,8 @@ module Steep
443
452
  case member
444
453
  when AST::Signature::Members::Method
445
454
  if member.instance_method?
446
- if with_initialize || member.name != :initialize
447
- extra_attrs = member.name == :initialize ? [:incompatible] : []
448
- add_method(module_name, member, methods: methods, extra_attributes: extra_attrs, current: namespace)
449
- end
455
+ extra_attrs = member.name == :initialize ? [:incompatible, :private] : []
456
+ add_method(module_name, member, methods: methods, extra_attributes: extra_attrs, current: namespace)
450
457
  end
451
458
  when AST::Signature::Members::Ivar
452
459
  merge_ivars(ivar_chains,
@@ -456,6 +463,24 @@ module Steep
456
463
  end
457
464
  end
458
465
 
466
+ sig.members.each do |member|
467
+ case member
468
+ when AST::Signature::Members::MethodAlias
469
+ method = methods[member.original_name]
470
+ if method
471
+ methods[member.new_name] = Method.new(
472
+ type_name: module_name,
473
+ name: member.new_name,
474
+ types: method.types,
475
+ super_method: nil,
476
+ attributes: method.attributes
477
+ )
478
+ else
479
+ Steep.logger.error "Cannot alias find original method `#{member.original_name}` for `#{member.new_name}` in #{module_name} (#{member.location.name || '-'}:#{member.location})"
480
+ end
481
+ end
482
+ end
483
+
459
484
  signatures.find_extensions(sig.name).each do |ext|
460
485
  ext.members.each do |member|
461
486
  case member
@@ -59,9 +59,24 @@ module Steep
59
59
  end
60
60
  end
61
61
 
62
+ class PrivateOverrideError < StandardError
63
+ attr_reader :child_type
64
+ attr_reader :super_type
65
+ attr_reader :method_name
66
+
67
+ def initialize(child_type:, super_type:, method_name:)
68
+ @child_type = child_type
69
+ @super_type = super_type
70
+ @method_name = method_name
71
+
72
+ super "Public method `#{method_name}` cannot overriden to private: #{child_type} <: #{super_type}"
73
+ end
74
+ end
75
+
62
76
  def validate(check)
63
77
  methods.each do |_, method|
64
- validate_method(check, method)
78
+ validate_method_type(check, method)
79
+ validate_method_visibility method
65
80
  end
66
81
 
67
82
  ivar_chains.each do |name, chain|
@@ -92,7 +107,7 @@ module Steep
92
107
  validate_chain(check, name, chain.parent)
93
108
  end
94
109
 
95
- def validate_method(check, method)
110
+ def validate_method_type(check, method)
96
111
  if method.super_method && !method.incompatible?
97
112
  result = check.check_method(method.name,
98
113
  method,
@@ -102,7 +117,7 @@ module Steep
102
117
  constraints: Subtyping::Constraints.empty)
103
118
 
104
119
  if result.success?
105
- validate_method(check, method.super_method)
120
+ validate_method_type(check, method.super_method)
106
121
  else
107
122
  raise InvalidMethodOverrideError.new(type: type,
108
123
  current_method: method,
@@ -112,6 +127,20 @@ module Steep
112
127
  end
113
128
  end
114
129
 
130
+ def validate_method_visibility(method)
131
+ if (super_method = method.super_method)
132
+ if method.private? && !super_method.private?
133
+ raise PrivateOverrideError.new(
134
+ child_type: method.type_name,
135
+ super_type: super_method.type_name,
136
+ method_name: method.name
137
+ )
138
+ end
139
+
140
+ validate_method_visibility(super_method)
141
+ end
142
+ end
143
+
115
144
  def select_method_type(&block)
116
145
  self.class.new(
117
146
  type: type,
@@ -28,6 +28,10 @@ module Steep
28
28
  attributes.include?(:incompatible)
29
29
  end
30
30
 
31
+ def private?
32
+ attributes.include?(:private)
33
+ end
34
+
31
35
  def closed?
32
36
  types.all?(&:closed?)
33
37
  end
data/lib/steep/names.rb CHANGED
@@ -24,7 +24,7 @@ module Steep
24
24
  end
25
25
 
26
26
  def hash
27
- self.class.hash ^ name.hash ^ @absolute.hash
27
+ self.class.hash ^ name.hash ^ namespace.hash
28
28
  end
29
29
 
30
30
  alias eql? ==
data/lib/steep/parser.y CHANGED
@@ -3,7 +3,8 @@ class Steep::Parser
3
3
  token kCLASS kMODULE kINTERFACE kDEF kEND kNIL kBOOL kANY kVOID kTYPE
4
4
  kINCOMPATIBLE kAT_TYPE kAT_IMPLEMENTS kAT_DYNAMIC kCONST kVAR kRETURN
5
5
  kBLOCK kBREAK kMETHOD kSELF kSELFQ kATTR_READER kATTR_ACCESSOR kINSTANCE
6
- kINCLUDE kEXTEND kINSTANCE kIVAR kCONSTRUCTOR kNOCONSTRUCTOR kEXTENSION
6
+ kINCLUDE kEXTEND kINSTANCE kIVAR kCONSTRUCTOR kNOCONSTRUCTOR kEXTENSION kPRIVATE kALIAS
7
+ kSUPER
7
8
  tARROW tBANG tBAR tCOLON tCOMMA tDOT tEQ tGT tGVAR tHAT tINT
8
9
  tINTERFACE_NAME tIVAR_NAME tLBRACE tLBRACKET tIDENT tLPAREN tLT tROCKET
9
10
  tMINUS tOPERATOR tPERCENT tPLUS tQUESTION tRBRACE tRBRACKET
@@ -11,7 +12,7 @@ token kCLASS kMODULE kINTERFACE kDEF kEND kNIL kBOOL kANY kVOID kTYPE
11
12
  type_METHOD type_SIGNATURE type_ANNOTATION type_TYPE
12
13
  tQUALIFIED_MODULE_NAME tQUALIFIED_INTERFACE_NAME tQUALIFIED_ALIAS_NAME
13
14
 
14
- expect 1
15
+ expect 3
15
16
 
16
17
  rule
17
18
 
@@ -657,6 +658,7 @@ rule
657
658
  | ivar_member
658
659
  | attr_reader_member
659
660
  | attr_accessor_member
661
+ | alias_member
660
662
 
661
663
  ivar_member: tIVAR_NAME tCOLON type
662
664
  {
@@ -751,6 +753,15 @@ rule
751
753
  result = AST::Signature::Members::Attr.new(location: loc, name: val[1].value, kind: :accessor, ivar: val[2], type: val[4])
752
754
  }
753
755
 
756
+ alias_member: kALIAS method_name method_name {
757
+ loc = val[0].location + val[2].location
758
+ result = AST::Signature::Members::MethodAlias.new(
759
+ location: loc,
760
+ new_name: val[1].value,
761
+ original_name: val[2].value
762
+ )
763
+ }
764
+
754
765
  attr_ivar_opt: # nothing
755
766
  {
756
767
  result = nil
@@ -790,6 +801,10 @@ rule
790
801
  {
791
802
  result = val[0].value
792
803
  }
804
+ | kPRIVATE
805
+ {
806
+ result = val[0].value
807
+ }
793
808
 
794
809
  super_class: module_name
795
810
  {
@@ -840,6 +855,10 @@ rule
840
855
  {
841
856
  result = [val[0]]
842
857
  }
858
+ | kSUPER
859
+ {
860
+ result = [AST::MethodType::Super.new(location: val[0].location)]
861
+ }
843
862
  | method_type tBAR method_type_union
844
863
  {
845
864
  result = [val[0]] + val[2]
@@ -908,6 +927,7 @@ rule
908
927
  | kMETHOD
909
928
  | kBOOL
910
929
  | kTYPE
930
+ | kALIAS
911
931
  | kCONSTRUCTOR
912
932
  {
913
933
  result = LocatedValue.new(location: val[0].location, value: :constructor)
@@ -919,6 +939,7 @@ rule
919
939
  | kATTR_READER
920
940
  | kATTR_ACCESSOR
921
941
  | kINCOMPATIBLE
942
+ | kPRIVATE
922
943
 
923
944
  annotation: kAT_TYPE kVAR subject tCOLON type
924
945
  {
@@ -1203,6 +1224,12 @@ def next_token
1203
1224
  new_token(:kINSTANCE, :instance)
1204
1225
  when input.scan(/ivar\b/)
1205
1226
  new_token(:kIVAR, :ivar)
1227
+ when input.scan(/private\b/)
1228
+ new_token(:kPRIVATE, :private)
1229
+ when input.scan(/alias\b/)
1230
+ new_token(:kALIAS, :alias)
1231
+ when input.scan(/super\b/)
1232
+ new_token(:kSUPER, :super)
1206
1233
  when input.scan(/%/)
1207
1234
  new_token(:tPERCENT, :%)
1208
1235
  when input.scan(/-/)
@@ -603,8 +603,8 @@ module Steep
603
603
  end
604
604
  end
605
605
 
606
- def resolve_instance(type, self_type:, instance_type:, module_type:, with_initialize: false)
607
- abstract_interface = builder.build_instance(type.name, with_initialize: with_initialize)
606
+ def resolve_instance(type, self_type:, instance_type:, module_type:, with_private: false)
607
+ abstract_interface = builder.build_instance(type.name).without_private(!with_private)
608
608
 
609
609
  module_type = module_type || case builder.signatures.find_class_or_module(type.name)
610
610
  when AST::Signature::Class
@@ -621,7 +621,7 @@ module Steep
621
621
  )
622
622
  end
623
623
 
624
- def resolve(type, self_type: type, instance_type: nil, module_type: nil)
624
+ def resolve(type, self_type: type, instance_type: nil, module_type: nil, with_private: false)
625
625
  Steep.logger.debug("Check#resolve: type=#{type}")
626
626
  case type
627
627
  when AST::Types::Any, AST::Types::Var, AST::Types::Class, AST::Types::Instance
@@ -631,14 +631,19 @@ module Steep
631
631
  resolve(type.back_type,
632
632
  self_type: self_type,
633
633
  instance_type: instance_type,
634
- module_type: module_type)
634
+ module_type: module_type,
635
+ with_private: with_private)
635
636
 
636
637
  when AST::Types::Name::Instance
637
- resolve_instance(type, self_type: self_type, instance_type: instance_type, module_type: module_type)
638
+ resolve_instance(type,
639
+ self_type: self_type,
640
+ instance_type: instance_type,
641
+ module_type: module_type,
642
+ with_private: with_private)
638
643
 
639
644
  when AST::Types::Name::Class
640
645
  yield_self do
641
- abstract_interface = builder.build_class(type.name, constructor: type.constructor)
646
+ abstract_interface = builder.build_class(type.name, constructor: type.constructor).without_private(!with_private)
642
647
 
643
648
  unless instance_type
644
649
  type_params = builder.signatures.find_class(type.name).params&.variables || []
@@ -662,7 +667,7 @@ module Steep
662
667
 
663
668
  when AST::Types::Name::Module
664
669
  yield_self do
665
- abstract_interface = builder.build_module(type.name)
670
+ abstract_interface = builder.build_module(type.name).without_private(!with_private)
666
671
 
667
672
  unless instance_type
668
673
  type_params = builder.signatures.find_module(type.name).params&.variables || []
@@ -697,13 +702,17 @@ module Steep
697
702
  end
698
703
 
699
704
  when AST::Types::Name::Alias
700
- resolve(expand_alias(type), self_type: self_type, instance_type: instance_type, module_type: module_type)
705
+ resolve(expand_alias(type),
706
+ self_type: self_type,
707
+ instance_type: instance_type,
708
+ module_type: module_type,
709
+ with_private: with_private)
701
710
 
702
711
  when AST::Types::Union
703
712
  interfaces = type.types.map do |member_type|
704
713
  fresh = AST::Types::Var.fresh(:___)
705
714
 
706
- resolve(member_type, self_type: type, instance_type: fresh, module_type: fresh).select_method_type do |method_type|
715
+ resolve(member_type, self_type: type, instance_type: fresh, module_type: fresh, with_private: with_private).select_method_type do |method_type|
707
716
  !method_type.each_type.include?(fresh)
708
717
  end
709
718
  end
@@ -772,7 +781,9 @@ module Steep
772
781
  ivar_chains: {})
773
782
 
774
783
  when AST::Types::Intersection
775
- interfaces = type.types.map do |type| resolve(type) end
784
+ interfaces = type.types.map do |type|
785
+ resolve(type, with_private: with_private)
786
+ end
776
787
 
777
788
  methods = interfaces.inject(nil) do |methods, i|
778
789
  if methods
@@ -825,7 +836,7 @@ module Steep
825
836
  yield_self do
826
837
  element_type = AST::Types::Union.build(types: type.types)
827
838
  array_type = AST::Builtin::Array.instance_type(element_type)
828
- array_interface = resolve(array_type, self_type: self_type)
839
+ array_interface = resolve(array_type, self_type: self_type, with_private: with_private)
829
840
 
830
841
  array_interface.methods[:[]] = array_interface.methods[:[]].yield_self do |aref|
831
842
  types = type.types.map.with_index {|elem_type, index|
@@ -870,7 +881,7 @@ module Steep
870
881
  yield_self do
871
882
  key_type = AST::Types::Union.build(types: type.elements.keys.map {|val| AST::Types::Literal.new(value: val) })
872
883
  value_type = AST::Types::Union.build(types: type.elements.values)
873
- hash_interface = resolve(AST::Builtin::Hash.instance_type(key_type, value_type), self_type: self_type)
884
+ hash_interface = resolve(AST::Builtin::Hash.instance_type(key_type, value_type), self_type: self_type, with_private: with_private)
874
885
 
875
886
  hash_interface.methods[:[]] = hash_interface.methods[:[]].yield_self do |ref|
876
887
  types = type.elements.map do |key, value_type|
@@ -915,7 +926,7 @@ module Steep
915
926
 
916
927
  when AST::Types::Proc
917
928
  yield_self do
918
- proc_interface = resolve(type.back_type, self_type: self_type)
929
+ proc_interface = resolve(type.back_type, self_type: self_type, with_private: with_private)
919
930
  apply_type = Interface::MethodType.new(
920
931
  type_params: [],
921
932
  params: type.params,
@@ -124,7 +124,7 @@ module Steep
124
124
  self_type: self_type,
125
125
  instance_type: self_type,
126
126
  module_type: class_type,
127
- with_initialize: true)
127
+ with_private: true)
128
128
  end
129
129
  else
130
130
  checker.resolve(self_type)
@@ -398,7 +398,7 @@ module Steep
398
398
  class_name = implement_module_name.name
399
399
  class_args = implement_module_name.args.map {|x| AST::Types::Var.new(name: x) }
400
400
 
401
- _ = checker.builder.build_instance(class_name, with_initialize: true)
401
+ _ = checker.builder.build_instance(class_name)
402
402
 
403
403
  instance_type = AST::Types::Name::Instance.new(name: class_name, args: class_args)
404
404
  module_type = AST::Types::Name::Class.new(name: class_name, constructor: true)
@@ -525,9 +525,12 @@ module Steep
525
525
  var = node.children[0]
526
526
  rhs = node.children[1]
527
527
 
528
- if var.name == :_
528
+ case var.name
529
+ when :_, :__any__
529
530
  synthesize(rhs, hint: AST::Builtin.any_type)
530
531
  typing.add_typing(node, AST::Builtin.any_type)
532
+ when :__skip__
533
+ typing.add_typing(node, AST::Builtin.any_type)
531
534
  else
532
535
  type_assignment(var, rhs, node, hint: hint)
533
536
  end
@@ -1767,7 +1770,7 @@ module Steep
1767
1770
 
1768
1771
  else
1769
1772
  begin
1770
- interface = checker.resolve(receiver_type)
1773
+ interface = checker.resolve(receiver_type, with_private: !receiver)
1771
1774
 
1772
1775
  method = interface.methods[method_name]
1773
1776
 
data/lib/steep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -0,0 +1,2 @@
1
+ # @type var x: NumberLike
2
+ x = 1 + NumberLike.new
@@ -0,0 +1,8 @@
1
+ class NumberLike
2
+ def to_number: -> Integer
3
+ end
4
+
5
+ extension Integer (NumberLike)
6
+ def +: (NumberLike) -> NumberLike
7
+ | super
8
+ end
@@ -6,7 +6,7 @@ class A
6
6
  end
7
7
 
8
8
  def foo()
9
- # !expects NoMethodError: type=::A, method=initialize
9
+ # initialize is a private method, so can be called here
10
10
  initialize()
11
11
  end
12
12
  end
@@ -0,0 +1,15 @@
1
+ __skip__ = begin
2
+ self.no_such_method
3
+ end
4
+
5
+ # @type var foo: String
6
+
7
+ foo = _ = begin
8
+ # !expects NoMethodError: type=::Object, method=no_such_method
9
+ self.no_such_method
10
+ end
11
+
12
+ foo = __any__ = begin
13
+ # !expects NoMethodError: type=::Object, method=no_such_method
14
+ self.no_such_method
15
+ end
data/stdlib/builtin.rbi CHANGED
@@ -413,9 +413,8 @@ module Enumerable<'a, 'b> : _Iteratable<'a, 'b>
413
413
  def collect: <'x> { ('a) -> 'x } -> Array<'x>
414
414
  | <'x> -> Enumerator<'a, Array<'x>>
415
415
 
416
- def map: <'x> { ('a) -> 'x } -> Array<'x>
417
- | <'x> -> Enumerator<'a, Array<'x>>
418
-
416
+ alias map collect
417
+
419
418
  def flat_map: <'x> { ('a) -> Array<'x> } -> Array<'x>
420
419
  | <'x> -> Enumerator<'a, Array<'x>>
421
420
 
@@ -737,7 +736,7 @@ class Set<'a>
737
736
  def clear: -> self
738
737
 
739
738
  def collect!: { ('a) -> 'a } -> self
740
- def map!: { ('a) -> 'a } -> self
739
+ alias map! collect!
741
740
 
742
741
  def delete: (any) -> self
743
742
  def delete?: (any) -> self?
@@ -761,7 +760,7 @@ class Set<'a>
761
760
  def keep_if: { ('a) -> any } -> self
762
761
 
763
762
  def size: -> Integer
764
- def length: -> Integer
763
+ alias length size
765
764
 
766
765
  def merge: (_Iteratable<'a, any>) -> self
767
766
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -259,6 +259,8 @@ files:
259
259
  - smoke/extension/b.rb
260
260
  - smoke/extension/c.rb
261
261
  - smoke/extension/d.rb
262
+ - smoke/extension/e.rb
263
+ - smoke/extension/e.rbi
262
264
  - smoke/hash/a.rb
263
265
  - smoke/hash/a.rbi
264
266
  - smoke/hash/b.rb
@@ -301,6 +303,7 @@ files:
301
303
  - smoke/rescue/a.rb
302
304
  - smoke/self/a.rb
303
305
  - smoke/self/a.rbi
306
+ - smoke/skip/skip.rb
304
307
  - smoke/stdout/a.rb
305
308
  - smoke/stdout/a.rbi
306
309
  - smoke/super/a.rb