steep 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5aa3a8e2257e84d0ed22ede78f6ddc038a43bada5127863bf308ec00e5cb2ca6
4
- data.tar.gz: fc29cc0b62e9a9c0bfdf3e1a2093e50bb6a53c474ca5de9472a7297694f6f020
3
+ metadata.gz: e93086efe3704ac8b59a1450fda301b7ab91f409c13c53a679a2ed3b3419ca84
4
+ data.tar.gz: b00e2030a9ea2171b6f967c78f469204c903cb937d421e5dcab896021fce2919
5
5
  SHA512:
6
- metadata.gz: 827e7bf852501b156d0f77b4120401ad02a5ed070335342d7b316f37c286f347cc183e2f1a68849c9f0d2f78cdd53d64a0a8151f2958d8b7562fda0afb256ccc
7
- data.tar.gz: 72444df723fe5ffaf552e6e5e92e7318c71d5ed9b2d77048faa928368626423b59ed9046b4a16cc916819f4fef8343b5e1866f9715ed95c701770dc49ec6a47d
6
+ metadata.gz: 06023d31b509f58efdea8c8f0e13c49b38f3a4936debbe3a0d88bfd84b356e7a761506a8f105c035bd454a4b2f39ae6af13d16b84d29e6d0050d9d58d7062e82
7
+ data.tar.gz: '0601459d31ad8ca758c95c29215eb237b5bc50490b5133e574057ec1836396d9189c3dd22628244c1d8d432e0f945a746c280ae96ca20b768c063fbae0c696af'
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.33.0 (2020-10-13)
6
+
7
+ * Make `!` typing flow sensitive ([#240](https://github.com/soutaro/steep/pull/240))
8
+
5
9
  ## 0.32.0 (2020-10-09)
6
10
 
7
11
  * Let type-case support interface types ([#237](https://github.com/soutaro/steep/pull/237))
@@ -16,7 +16,6 @@ require 'uri'
16
16
 
17
17
  require "rbs"
18
18
 
19
- require "steep/ast/location"
20
19
  require "steep/ast/types/helper"
21
20
  require "steep/ast/types/any"
22
21
  require "steep/ast/types/instance"
@@ -39,7 +38,6 @@ require "steep/ast/types/logic"
39
38
  require "steep/ast/type_params"
40
39
  require "steep/ast/annotation"
41
40
  require "steep/ast/annotation/collection"
42
- require "steep/ast/buffer"
43
41
  require "steep/ast/builtin"
44
42
  require "steep/ast/types/factory"
45
43
 
@@ -342,44 +342,44 @@ module Steep
342
342
  end
343
343
  end
344
344
 
345
+ NilClassName = TypeName("::NilClass")
346
+
345
347
  def setup_primitives(method_name, method_type)
346
348
  if method_def = method_type.method_def
347
349
  defined_in = method_def.defined_in
348
350
  member = method_def.member
349
351
 
350
352
  if member.is_a?(RBS::AST::Members::MethodDefinition)
351
- case
352
- when defined_in == RBS::BuiltinNames::Object.name && member.instance?
353
- case method_name
354
- when :is_a?, :kind_of?, :instance_of?
353
+ case method_name
354
+ when :is_a?, :kind_of?, :instance_of?
355
+ if defined_in == RBS::BuiltinNames::Object.name && member.instance?
355
356
  return method_type.with(
356
357
  return_type: AST::Types::Logic::ReceiverIsArg.new(location: method_type.return_type.location)
357
358
  )
358
- when :nil?
359
- return method_type.with(
360
- return_type: AST::Types::Logic::ReceiverIsNil.new(location: method_type.return_type.location)
361
- )
362
359
  end
363
360
 
364
- when defined_in == AST::Builtin::NilClass.module_name && member.instance?
365
- case method_name
366
- when :nil?
361
+ when :nil?
362
+ case defined_in
363
+ when RBS::BuiltinNames::Object.name,
364
+ NilClassName
367
365
  return method_type.with(
368
366
  return_type: AST::Types::Logic::ReceiverIsNil.new(location: method_type.return_type.location)
369
367
  )
370
368
  end
371
369
 
372
- when defined_in == RBS::BuiltinNames::BasicObject.name && member.instance?
373
- case method_name
374
- when :!
370
+ when :!
371
+ case defined_in
372
+ when RBS::BuiltinNames::BasicObject.name,
373
+ RBS::BuiltinNames::TrueClass.name,
374
+ RBS::BuiltinNames::FalseClass.name
375
375
  return method_type.with(
376
376
  return_type: AST::Types::Logic::Not.new(location: method_type.return_type.location)
377
377
  )
378
378
  end
379
379
 
380
- when defined_in == RBS::BuiltinNames::Module.name && member.instance?
381
- case method_name
382
- when :===
380
+ when :===
381
+ case defined_in
382
+ when RBS::BuiltinNames::Module.name
383
383
  return method_type.with(
384
384
  return_type: AST::Types::Logic::ArgIsReceiver.new(location: method_type.return_type.location)
385
385
  )
@@ -409,7 +409,7 @@ module Steep
409
409
  else
410
410
  raise "Unexpected `self` type interface"
411
411
  end
412
-
412
+
413
413
  when Name::Instance
414
414
  Interface::Interface.new(type: self_type, private: private).tap do |interface|
415
415
  definition = definition_builder.build_instance(type.name)
@@ -13,7 +13,7 @@ module Steep
13
13
  if range
14
14
  text = text.dup
15
15
 
16
- buf = AST::Buffer.new(name: :_, content: text)
16
+ buf = RBS::Buffer.new(name: :_, content: text)
17
17
 
18
18
  start_pos = buf.loc_to_pos(range[:start].yield_self {|pos| [pos[:line]+1, pos[:character]] })
19
19
  end_pos = buf.loc_to_pos(range[:end].yield_self {|pos| [pos[:line]+1, pos[:character]] })
@@ -65,11 +65,11 @@ module Steep
65
65
  parser.tokenize(buffer)
66
66
  end
67
67
 
68
- buffer = AST::Buffer.new(name: path, content: source_code)
68
+ buffer = RBS::Buffer.new(name: path, content: source_code)
69
69
 
70
70
  comments.each do |comment|
71
71
  src = comment.text.gsub(/\A#\s*/, '')
72
- location = AST::Location.new(buffer: buffer,
72
+ location = RBS::Location.new(buffer: buffer,
73
73
  start_pos: comment.location.expression.begin_pos + 1,
74
74
  end_pos: comment.location.expression.end_pos)
75
75
  annotation = AnnotationParser.new(factory: factory).parse(src, location: location)
@@ -29,7 +29,7 @@ module Steep
29
29
  else
30
30
  ""
31
31
  end
32
- buffer = AST::Buffer.new(name: source.path, content: content)
32
+ buffer = RBS::Buffer.new(name: source.path, content: content)
33
33
  new(buffer: buffer, context: context, range: range || 0..buffer.content.size)
34
34
  end
35
35
 
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.32.0"
2
+ VERSION = "0.33.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ class Fun
2
+ def foo(v)
3
+ !v.nil? && foo2(v)
4
+ end
5
+
6
+ def foo2(_)
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ class Fun
2
+ def foo: (Integer?) -> void
3
+ def foo2: (Integer) -> void
4
+ end
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.32.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -140,9 +140,7 @@ files:
140
140
  - lib/steep/annotation_parser.rb
141
141
  - lib/steep/ast/annotation.rb
142
142
  - lib/steep/ast/annotation/collection.rb
143
- - lib/steep/ast/buffer.rb
144
143
  - lib/steep/ast/builtin.rb
145
- - lib/steep/ast/location.rb
146
144
  - lib/steep/ast/type_params.rb
147
145
  - lib/steep/ast/types.rb
148
146
  - lib/steep/ast/types/any.rb
@@ -331,6 +329,8 @@ files:
331
329
  - smoke/regexp/b.rb
332
330
  - smoke/regression/Steepfile
333
331
  - smoke/regression/array.rb
332
+ - smoke/regression/fun.rb
333
+ - smoke/regression/fun.rbs
334
334
  - smoke/regression/hash.rb
335
335
  - smoke/regression/poly_new.rb
336
336
  - smoke/regression/poly_new.rbs
@@ -363,7 +363,7 @@ metadata:
363
363
  homepage_uri: https://github.com/soutaro/steep
364
364
  source_code_uri: https://github.com/soutaro/steep
365
365
  changelog_uri: https://github.com/soutaro/steep/blob/master/CHANGELOG.md
366
- post_install_message:
366
+ post_install_message:
367
367
  rdoc_options: []
368
368
  require_paths:
369
369
  - lib
@@ -378,8 +378,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
378
378
  - !ruby/object:Gem::Version
379
379
  version: '0'
380
380
  requirements: []
381
- rubygems_version: 3.0.6
382
- signing_key:
381
+ rubygems_version: 3.1.2
382
+ signing_key:
383
383
  specification_version: 4
384
384
  summary: Gradual Typing for Ruby
385
385
  test_files: []
@@ -1,51 +0,0 @@
1
- module Steep
2
- module AST
3
- class Buffer
4
- attr_reader :name
5
- attr_reader :content
6
- attr_reader :lines
7
- attr_reader :ranges
8
-
9
- def initialize(name:, content:)
10
- @name = name
11
- @content = content
12
-
13
- @lines = content.split(/\n/, -1)
14
-
15
- @ranges = []
16
- offset = 0
17
- lines.each.with_index do |line, index|
18
- if index == lines.size - 1
19
- ranges << (offset..offset)
20
- else
21
- size = line.size
22
- range = offset..(offset+size)
23
- ranges << range
24
- offset += size+1
25
- end
26
- end
27
- end
28
-
29
- def pos_to_loc(pos)
30
- index = ranges.bsearch_index do |range|
31
- pos <= range.end
32
- end
33
-
34
- if index
35
- [index + 1, pos - ranges[index].begin]
36
- else
37
- [1, pos]
38
- end
39
- end
40
-
41
- def loc_to_pos(loc)
42
- line, column = loc
43
- ranges[line - 1].begin + column
44
- end
45
-
46
- def source(range)
47
- content[range]
48
- end
49
- end
50
- end
51
- end
@@ -1,86 +0,0 @@
1
- module Steep
2
- module AST
3
- class Location
4
- attr_reader :buffer
5
- attr_reader :start_pos
6
- attr_reader :end_pos
7
-
8
- def initialize(buffer:, start_pos:, end_pos:)
9
- @buffer = buffer
10
- @start_pos = start_pos
11
- @end_pos = end_pos
12
- end
13
-
14
- def inspect
15
- "#<#{self.class}:#{self.__id__} @buffer=#{buffer.name}, @start_pos=#{start_pos}, @end_pos=#{end_pos}, source='#{source.lines.first}', start_line=#{start_line}, start_column=#{start_column}>"
16
- end
17
-
18
- def name
19
- buffer.name
20
- end
21
-
22
- def start_line
23
- start_loc[0]
24
- end
25
-
26
- def start_column
27
- start_loc[1]
28
- end
29
-
30
- def end_line
31
- end_loc[0]
32
- end
33
-
34
- def end_column
35
- end_loc[1]
36
- end
37
-
38
- def start_loc
39
- @start_loc ||= buffer.pos_to_loc(start_pos)
40
- end
41
-
42
- def end_loc
43
- @end_loc ||= buffer.pos_to_loc(end_pos)
44
- end
45
-
46
- def source
47
- @source ||= buffer.source(start_pos...end_pos)
48
- end
49
-
50
- def to_s
51
- "#{start_line}:#{start_column}...#{end_line}:#{end_column}"
52
- end
53
-
54
- def ==(other)
55
- other.is_a?(Location) &&
56
- other.buffer == buffer &&
57
- other.start_pos == start_pos &&
58
- other.end_pos == end_pos
59
- end
60
-
61
- def +(other)
62
- if other
63
- raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer
64
-
65
- self.class.new(buffer: buffer,
66
- start_pos: start_pos,
67
- end_pos: other.end_pos)
68
- else
69
- self
70
- end
71
- end
72
-
73
- def self.concat(*locations)
74
- locations.inject {|l1, l2|
75
- l1 + l2
76
- }
77
- end
78
-
79
- def pred?(loc)
80
- loc.is_a?(Location) &&
81
- loc.name == name &&
82
- loc.start_pos == end_pos
83
- end
84
- end
85
- end
86
- end