steep 1.0.0 → 1.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-windows.yml +34 -0
  3. data/.github/workflows/ruby.yml +7 -2
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +59 -0
  6. data/Gemfile +7 -4
  7. data/Gemfile.lock +17 -21
  8. data/Gemfile.steep +3 -0
  9. data/Gemfile.steep.lock +49 -0
  10. data/Rakefile +5 -0
  11. data/Steepfile +6 -1
  12. data/bin/setup +2 -0
  13. data/bin/steep +19 -0
  14. data/lib/steep/ast/builtin.rb +2 -2
  15. data/lib/steep/ast/types/factory.rb +7 -3
  16. data/lib/steep/ast/types/proc.rb +2 -0
  17. data/lib/steep/cli.rb +3 -1
  18. data/lib/steep/diagnostic/ruby.rb +50 -4
  19. data/lib/steep/diagnostic/signature.rb +18 -0
  20. data/lib/steep/drivers/check.rb +3 -3
  21. data/lib/steep/drivers/watch.rb +3 -1
  22. data/lib/steep/method_name.rb +9 -3
  23. data/lib/steep/node_helper.rb +49 -0
  24. data/lib/steep/path_helper.rb +22 -0
  25. data/lib/steep/project.rb +3 -15
  26. data/lib/steep/server/base_worker.rb +1 -0
  27. data/lib/steep/server/change_buffer.rb +1 -1
  28. data/lib/steep/server/interaction_worker.rb +3 -5
  29. data/lib/steep/server/master.rb +61 -45
  30. data/lib/steep/server/type_check_worker.rb +10 -25
  31. data/lib/steep/services/completion_provider.rb +25 -18
  32. data/lib/steep/services/goto_service.rb +2 -4
  33. data/lib/steep/services/hover_provider/rbs.rb +1 -1
  34. data/lib/steep/services/hover_provider/ruby.rb +30 -12
  35. data/lib/steep/services/stats_calculator.rb +0 -1
  36. data/lib/steep/services/type_check_service.rb +15 -12
  37. data/lib/steep/shims/symbol_start_with.rb +18 -0
  38. data/lib/steep/signature/validator.rb +25 -1
  39. data/lib/steep/source.rb +1 -1
  40. data/lib/steep/subtyping/check.rb +0 -3
  41. data/lib/steep/subtyping/constraints.rb +43 -14
  42. data/lib/steep/type_construction.rb +721 -764
  43. data/lib/steep/type_inference/constant_env.rb +0 -2
  44. data/lib/steep/type_inference/context.rb +23 -17
  45. data/lib/steep/type_inference/logic_type_interpreter.rb +210 -117
  46. data/lib/steep/type_inference/method_call.rb +80 -6
  47. data/lib/steep/type_inference/multiple_assignment.rb +189 -0
  48. data/lib/steep/type_inference/send_args.rb +1 -2
  49. data/lib/steep/type_inference/type_env.rb +273 -116
  50. data/lib/steep/type_inference/type_env_builder.rb +138 -0
  51. data/lib/steep/typing.rb +2 -0
  52. data/lib/steep/version.rb +1 -1
  53. data/lib/steep.rb +7 -5
  54. data/rbs_collection.steep.lock.yaml +112 -0
  55. data/rbs_collection.steep.yaml +19 -0
  56. data/sample/sig/conference.rbs +8 -0
  57. data/sig/shims/parser/source/map.rbs +146 -0
  58. data/sig/shims/parser/source/range.rbs +237 -0
  59. data/sig/shims/parser.rbs +17 -0
  60. data/sig/steep/ast/annotation/collection.rbs +75 -0
  61. data/sig/steep/ast/annotation.rbs +126 -0
  62. data/sig/steep/ast/builtin.rbs +69 -0
  63. data/sig/steep/ast/type_params.rbs +11 -0
  64. data/sig/steep/ast/types/any.rbs +29 -0
  65. data/sig/steep/ast/types/boolean.rbs +31 -0
  66. data/sig/steep/ast/types/bot.rbs +29 -0
  67. data/sig/steep/ast/types/class.rbs +29 -0
  68. data/sig/steep/ast/types/factory.rbs +76 -0
  69. data/sig/steep/ast/types/helper.rbs +19 -0
  70. data/sig/steep/ast/types/instance.rbs +29 -0
  71. data/sig/steep/ast/types/intersection.rbs +35 -0
  72. data/sig/steep/ast/types/literal.rbs +33 -0
  73. data/sig/steep/ast/types/logic.rbs +78 -0
  74. data/sig/steep/ast/types/name.rbs +71 -0
  75. data/sig/steep/ast/types/nil.rbs +31 -0
  76. data/sig/steep/ast/types/proc.rbs +46 -0
  77. data/sig/steep/ast/types/record.rbs +38 -0
  78. data/sig/steep/ast/types/self.rbs +29 -0
  79. data/sig/steep/ast/types/top.rbs +29 -0
  80. data/sig/steep/ast/types/tuple.rbs +34 -0
  81. data/sig/steep/ast/types/union.rbs +38 -0
  82. data/sig/steep/ast/types/var.rbs +37 -0
  83. data/sig/steep/ast/types/void.rbs +29 -0
  84. data/sig/steep/ast/types.rbs +37 -0
  85. data/sig/steep/diagnostic/deprecated/unknown_constant_assigned.rbs +15 -0
  86. data/sig/steep/diagnostic/helper.rbs +9 -0
  87. data/sig/steep/diagnostic/lsp_formatter.rbs +29 -0
  88. data/sig/steep/diagnostic/ruby.rbs +494 -0
  89. data/sig/steep/diagnostic/signature.rbs +215 -0
  90. data/sig/steep/interface/block.rbs +35 -0
  91. data/sig/steep/interface/function.rbs +253 -0
  92. data/sig/steep/interface/interface.rbs +23 -0
  93. data/sig/steep/interface/method_type.rbs +55 -0
  94. data/sig/steep/interface/substitution.rbs +53 -0
  95. data/sig/steep/interface/type_param.rbs +35 -0
  96. data/sig/steep/method_name.rbs +26 -0
  97. data/sig/steep/module_helper.rbs +7 -0
  98. data/sig/steep/node_helper.rbs +11 -0
  99. data/sig/steep/project/dsl.rbs +94 -0
  100. data/sig/steep/project/options.rbs +15 -0
  101. data/sig/steep/project/pattern.rbs +25 -0
  102. data/sig/steep/project/target.rbs +25 -0
  103. data/sig/steep/project.rbs +19 -0
  104. data/sig/steep/services/completion_provider.rbs +123 -0
  105. data/sig/steep/services/content_change.rbs +35 -0
  106. data/sig/steep/services/file_loader.rbs +13 -0
  107. data/sig/steep/services/goto_service.rbs +45 -0
  108. data/sig/steep/services/hover_provider/rbs.rbs +21 -0
  109. data/sig/steep/services/hover_provider/ruby.rbs +109 -0
  110. data/sig/steep/services/hover_provider/singleton_methods.rbs +11 -0
  111. data/sig/steep/services/path_assignment.rbs +21 -0
  112. data/sig/steep/services/signature_service.rbs +91 -0
  113. data/sig/steep/services/stats_calculator.rbs +17 -0
  114. data/sig/steep/services/type_check_service.rbs +93 -0
  115. data/sig/steep/source.rbs +55 -0
  116. data/sig/steep/subtyping/cache.rbs +17 -0
  117. data/sig/steep/subtyping/check.rbs +93 -0
  118. data/sig/steep/subtyping/constraints.rbs +111 -0
  119. data/sig/steep/subtyping/relation.rbs +51 -0
  120. data/sig/steep/subtyping/result.rbs +157 -0
  121. data/sig/steep/subtyping/variable_variance.rbs +23 -0
  122. data/sig/steep/type_construction.rbs +285 -0
  123. data/sig/steep/type_inference/block_params.rbs +52 -0
  124. data/sig/steep/type_inference/constant_env.rbs +27 -0
  125. data/sig/steep/type_inference/context.rbs +137 -0
  126. data/sig/steep/type_inference/logic_type_interpreter.rbs +72 -0
  127. data/sig/steep/type_inference/method_call.rbs +124 -0
  128. data/sig/steep/type_inference/method_params.rbs +104 -0
  129. data/sig/steep/type_inference/multiple_assignment.rbs +76 -0
  130. data/sig/steep/type_inference/type_env.rbs +158 -0
  131. data/sig/steep/type_inference/type_env_builder.rbs +77 -0
  132. data/sig/steep/typing.rbs +68 -0
  133. data/sig/steep.rbs +31 -0
  134. data/smoke/class/f.rb +1 -0
  135. data/smoke/class/test_expectations.yml +2 -2
  136. data/smoke/diagnostics/test_expectations.yml +4 -2
  137. data/smoke/regression/lambda.rb +3 -0
  138. data/smoke/regression/test_expectations.yml +12 -0
  139. data/steep.gemspec +1 -1
  140. metadata +95 -9
  141. data/lib/steep/subtyping/variable_occurrence.rb +0 -51
  142. data/lib/steep/type_inference/local_variable_type_env.rb +0 -249
  143. data/lib/steep/type_inference/logic.rb +0 -161
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 899bca0fd211114d52e015acc844ee4648eadb6b739af911f7ac73560cedef83
4
- data.tar.gz: 2fe5b52342a6b932d5ce08f5b78c417e43cda38db378c35d1b31891ca7c79465
3
+ metadata.gz: d1094b2c84b950883393bb887dbc8476ba59d911ebee1d358c605e9110bfae8f
4
+ data.tar.gz: 54fbfd4ea0120bcc45766f530a4c381c9b79c78929a7aa749059d03e69bf7eae
5
5
  SHA512:
6
- metadata.gz: 20e09462ddef35a3aa00a19d6f7cb86f2862c9ab700131bf439fc7750b088d43d1f2bb3380dfdf57a0c881d58c885b789d47eba35d7e146156809511e4e1c64c
7
- data.tar.gz: dfa20a13b3b25575419ad1c9ac2417b1b873a0732eded5fa643e6e5768b644e27ea07c8d83bf9ae5e333b872d8f039aba111bee4d7ae2a48034dc06047265fee
6
+ metadata.gz: 3b4d09f5d02029a75099f541e27194f88fcb0eb50fa69fbc6cfa030b7b6ee83873cfff9478a781ff7a12ea94c45ea5c4ca31aed10bf065ce960dbdbf11ebd918
7
+ data.tar.gz: 8ddfdbdab223a916a6b42715f16df891aed80f107f96c19aa8a53ce8bafa8172888fd992a52bf5d4bba38e2ae8ff7484f1a823586d89e2e267854e84d8fd0222
@@ -0,0 +1,34 @@
1
+ name: Run test on Windows
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request: {}
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ matrix:
13
+ ruby_version:
14
+ - "2.7"
15
+ - "3.0"
16
+ - "3.1"
17
+ task:
18
+ - test
19
+ # - test:output Ignored because the order of diagnostics changes somehow
20
+ - build
21
+ runs-on: windows-latest
22
+ steps:
23
+ - uses: actions/checkout@v3
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby_version }}
27
+ - name: Run test
28
+ run: |
29
+ git config --global --add safe.directory /__w/steep/steep
30
+ ruby -v
31
+ gem install bundler
32
+ bundle install --jobs 4 --retry 3
33
+ bin/setup
34
+ bundle exec rake ${{matrix.task}}
@@ -1,4 +1,4 @@
1
- name: Ruby
1
+ name: Run test on container
2
2
 
3
3
  on:
4
4
  push:
@@ -8,10 +8,10 @@ on:
8
8
 
9
9
  jobs:
10
10
  test:
11
- runs-on: "ubuntu-latest"
12
11
  strategy:
13
12
  matrix:
14
13
  container_tag:
14
+ - "2.6"
15
15
  - "2.7"
16
16
  - "3.0"
17
17
  - "3.1"
@@ -20,10 +20,15 @@ jobs:
20
20
  - test
21
21
  - test:output
22
22
  - build
23
+ runs-on: ubuntu-latest
23
24
  container:
24
25
  image: rubylang/ruby:${{ matrix.container_tag }}
25
26
  steps:
26
27
  - uses: actions/checkout@v3
28
+ - name: Reset bundler
29
+ run: |
30
+ rm Gemfile.lock Gemfile.steep.lock
31
+ if: contains(matrix.container_tag, '2.6')
27
32
  - name: Run test
28
33
  run: |
29
34
  git config --global --add safe.directory /__w/steep/steep
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /lib/steep/parser.output
10
10
  /lib/steep/parser.rb
11
11
  /log
12
+ /.gem_rbs_collection
data/CHANGELOG.md CHANGED
@@ -2,6 +2,65 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.1.0.pre.1 (2022-07-26)
6
+
7
+ ### Type checker core
8
+
9
+ * Type refinement with method calls ([#590](https://github.com/soutaro/steep/issues/590))
10
+ * Better multiple assignment type checking ([\#605](https://github.com/soutaro/steep/pull/605))
11
+ * Fix generics issues around proc types ([\#609](https://github.com/soutaro/steep/pull/609), [\#611](https://github.com/soutaro/steep/pull/611))
12
+ * Fix type application validation ([#607](https://github.com/soutaro/steep/pull/607); backport from 1.0.2)
13
+ * Add class variable validation ([\#593](https://github.com/soutaro/steep/pull/593))
14
+ * Fix type application validation ([\#607](https://github.com/soutaro/steep/pull/607))
15
+
16
+ ### Commandline tool
17
+
18
+ * Appends "done!" to the watch output when the type check is complete ([\#596](https://github.com/soutaro/steep/pull/596))
19
+
20
+ ### Language server
21
+
22
+ * Fix hover on multiple assignment ([\#606](https://github.com/soutaro/steep/pull/606))
23
+
24
+ ## 1.0.2 (2022-07-19)
25
+
26
+ This is another patch release for Steep 1.0.
27
+
28
+ ### Type checker core
29
+
30
+ * Fix type application validation ([#607](https://github.com/soutaro/steep/pull/607))
31
+
32
+ ## 1.0.1 (2022-06-16)
33
+
34
+ This is the first patch release for Steep 1.0.
35
+ However, this release includes one non-trivial type system update, [\#570](https://github.com/soutaro/steep/pull/570), which adds a special typing rule for `Hash#compact` like `Array#compact`.
36
+ The change will make type checking more permissive and precise, so no new error won't be reported with the fix.
37
+
38
+ ### Type checker core
39
+
40
+ * Support shorthand hash for Ruby 3.1 ([\#567](https://github.com/soutaro/steep/pull/567))
41
+ * Fix super and zsuper with block ([\#568](https://github.com/soutaro/steep/pull/568))
42
+ * Apply logic-type evaluation only if the node is `:send` ([\#569](https://github.com/soutaro/steep/pull/569))
43
+ * Add support for `Hash#compact` ([\#570](https://github.com/soutaro/steep/pull/570))
44
+ * Use given `const_env` when making a new `ModuleContext` ([\#575](https://github.com/soutaro/steep/pull/575))
45
+ * Graceful, hopefully, error handling with undefined outer module ([\#576](https://github.com/soutaro/steep/pull/576))
46
+ * Type check anonymous block forwarding ([\#577](https://github.com/soutaro/steep/pull/577))
47
+ * Incompatible default value is a type error ([\#578](https://github.com/soutaro/steep/pull/578))
48
+ * Load `ChildrenLevel` helper in `AST::Types::Proc` ([\#584](https://github.com/soutaro/steep/pull/584))
49
+ * Type check `gvar` and `gvasgn` in methods([\#579](https://github.com/soutaro/steep/pull/579))
50
+ * Avoid `UnexpectedError` when assigning untyped singleton class ([\#586](https://github.com/soutaro/steep/pull/586))
51
+
52
+ ### Commandline tool
53
+
54
+ * Improve Windows support ([\#561](https://github.com/soutaro/steep/pull/561), [\#573](https://github.com/soutaro/steep/pull/573))
55
+ * Test if `.ruby-version` exists before `rvm do` in binstub ([\#558](https://github.com/soutaro/steep/pull/558))
56
+ * Fix typo ([\#564](https://github.com/soutaro/steep/pull/564))
57
+ * Ignore `untitled:` URIs in LSP ([\#580](https://github.com/soutaro/steep/pull/580))
58
+
59
+ ### Miscellaneous
60
+
61
+ * Fix test name ([\#565](https://github.com/soutaro/steep/pull/565), [\#566](https://github.com/soutaro/steep/pull/566), [\#585](https://github.com/soutaro/steep/pull/585))
62
+ * Remove some unused code except tests ([\#587](https://github.com/soutaro/steep/pull/587))
63
+
5
64
  ## 1.0.0 (2022-05-20)
6
65
 
7
66
  * Add special typing rule for `Array#compact` ([\#555](https://github.com/soutaro/steep/pull/555))
data/Gemfile CHANGED
@@ -3,13 +3,16 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in steep.gemspec
4
4
  gemspec
5
5
 
6
- gem "with_steep_types", path: "test/gems/with_steep_types"
7
- gem "without_steep_types", path: "test/gems/without_steep_types"
8
-
9
6
  gem "rake"
10
- gem "minitest", "~> 5.15"
7
+ gem "minitest", "~> 5.16"
11
8
  gem "minitest-hooks"
12
9
  group :stackprof, optional: true do
13
10
  gem "stackprof"
14
11
  end
15
12
  gem 'minitest-slow_test'
13
+ gem "rbs", "~> 2.5.1"
14
+
15
+ group :ide, optional: true do
16
+ gem "ruby-debug-ide"
17
+ gem "debase", ">= 0.2.5.beta2"
18
+ end
data/Gemfile.lock CHANGED
@@ -1,44 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steep (1.0.0)
4
+ steep (1.1.0.pre.1)
5
5
  activesupport (>= 5.1)
6
6
  language_server-protocol (>= 3.15, < 4.0)
7
7
  listen (~> 3.0)
8
8
  parallel (>= 1.0.0)
9
- parser (>= 3.0)
9
+ parser (>= 3.1)
10
10
  rainbow (>= 2.2.2, < 4.0)
11
11
  rbs (>= 2.3.2)
12
12
  terminal-table (>= 2, < 4)
13
13
 
14
- PATH
15
- remote: test/gems/with_steep_types
16
- specs:
17
- with_steep_types (1.0.0)
18
-
19
- PATH
20
- remote: test/gems/without_steep_types
21
- specs:
22
- without_steep_types (1.0.0)
23
-
24
14
  GEM
25
15
  remote: https://rubygems.org/
26
16
  specs:
27
- activesupport (7.0.3)
17
+ activesupport (7.0.3.1)
28
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
29
19
  i18n (>= 1.6, < 2)
30
20
  minitest (>= 5.1)
31
21
  tzinfo (~> 2.0)
32
22
  ast (2.4.2)
33
23
  concurrent-ruby (1.1.10)
24
+ debase (0.2.5.beta2)
25
+ debase-ruby_core_source (>= 0.10.12)
26
+ debase-ruby_core_source (0.10.16)
34
27
  ffi (1.15.5)
35
- i18n (1.10.0)
28
+ i18n (1.12.0)
36
29
  concurrent-ruby (~> 1.0)
37
30
  language_server-protocol (3.16.0.3)
38
31
  listen (3.7.1)
39
32
  rb-fsevent (~> 0.10, >= 0.10.3)
40
33
  rb-inotify (~> 0.9, >= 0.9.10)
41
- minitest (5.15.0)
34
+ minitest (5.16.2)
42
35
  minitest-hooks (1.5.0)
43
36
  minitest (> 5.3)
44
37
  minitest-slow_test (0.2.0)
@@ -51,26 +44,29 @@ GEM
51
44
  rb-fsevent (0.11.1)
52
45
  rb-inotify (0.10.1)
53
46
  ffi (~> 1.0)
54
- rbs (2.4.0)
47
+ rbs (2.5.1)
48
+ ruby-debug-ide (0.7.3)
49
+ rake (>= 0.8.1)
55
50
  stackprof (0.2.19)
56
51
  terminal-table (3.0.2)
57
52
  unicode-display_width (>= 1.1.1, < 3)
58
- tzinfo (2.0.4)
53
+ tzinfo (2.0.5)
59
54
  concurrent-ruby (~> 1.0)
60
- unicode-display_width (2.1.0)
55
+ unicode-display_width (2.2.0)
61
56
 
62
57
  PLATFORMS
63
58
  ruby
64
59
 
65
60
  DEPENDENCIES
66
- minitest (~> 5.15)
61
+ debase (>= 0.2.5.beta2)
62
+ minitest (~> 5.16)
67
63
  minitest-hooks
68
64
  minitest-slow_test
69
65
  rake
66
+ rbs (~> 2.5.1)
67
+ ruby-debug-ide
70
68
  stackprof
71
69
  steep!
72
- with_steep_types!
73
- without_steep_types!
74
70
 
75
71
  BUNDLED WITH
76
72
  2.3.8
data/Gemfile.steep ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "steep"
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (7.0.3)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 1.6, < 2)
7
+ minitest (>= 5.1)
8
+ tzinfo (~> 2.0)
9
+ ast (2.4.2)
10
+ concurrent-ruby (1.1.10)
11
+ ffi (1.15.5)
12
+ i18n (1.10.0)
13
+ concurrent-ruby (~> 1.0)
14
+ language_server-protocol (3.16.0.3)
15
+ listen (3.7.1)
16
+ rb-fsevent (~> 0.10, >= 0.10.3)
17
+ rb-inotify (~> 0.9, >= 0.9.10)
18
+ minitest (5.16.2)
19
+ parallel (1.22.1)
20
+ parser (3.1.2.0)
21
+ ast (~> 2.4.1)
22
+ rainbow (3.1.1)
23
+ rb-fsevent (0.11.1)
24
+ rb-inotify (0.10.1)
25
+ ffi (~> 1.0)
26
+ rbs (2.6.0)
27
+ steep (1.0.1)
28
+ activesupport (>= 5.1)
29
+ language_server-protocol (>= 3.15, < 4.0)
30
+ listen (~> 3.0)
31
+ parallel (>= 1.0.0)
32
+ parser (>= 3.1)
33
+ rainbow (>= 2.2.2, < 4.0)
34
+ rbs (>= 2.3.2)
35
+ terminal-table (>= 2, < 4)
36
+ terminal-table (3.0.2)
37
+ unicode-display_width (>= 1.1.1, < 3)
38
+ tzinfo (2.0.4)
39
+ concurrent-ruby (~> 1.0)
40
+ unicode-display_width (2.2.0)
41
+
42
+ PLATFORMS
43
+ arm64-darwin-21
44
+
45
+ DEPENDENCIES
46
+ steep
47
+
48
+ BUNDLED WITH
49
+ 2.3.15
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
+ if ENV["VSCODE_CWD"]
5
+ require "minitest"
6
+ Minitest.seed = Time.now.to_i
7
+ end
8
+
4
9
  Rake::TestTask.new(:test) do |t|
5
10
  t.libs << "test"
6
11
  t.libs << "lib"
data/Steepfile CHANGED
@@ -1 +1,6 @@
1
- target :app do end
1
+ target :app do
2
+ check "lib"
3
+ signature "sig"
4
+
5
+ collection_config "rbs_collection.steep.yaml"
6
+ end
data/bin/setup CHANGED
@@ -5,3 +5,5 @@ set -vx
5
5
 
6
6
  bundle install
7
7
 
8
+ bundle install --gemfile=Gemfile.steep
9
+ bundle exec --gemfile=Gemfile.steep rbs --collection=rbs_collection.steep.yaml collection install
data/bin/steep ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bash
2
+
3
+ BINSTUB_DIR=$(cd $(dirname $0); pwd)
4
+ GEMFILE=$(readlink -f ${BINSTUB_DIR}/../Gemfile.steep)
5
+ ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/..)
6
+
7
+ STEEP="bundle exec --gemfile=${GEMFILE} steep"
8
+
9
+ if type "rbenv" > /dev/null 2>&1; then
10
+ STEEP="rbenv exec ${STEEP}"
11
+ else
12
+ if type "rvm" > /dev/null 2>&1; then
13
+ if [ -e ${ROOT_DIR}/.ruby-version ]; then
14
+ STEEP="rvm ${ROOT_DIR} do ${STEEP}"
15
+ fi
16
+ fi
17
+ fi
18
+
19
+ exec $STEEP $@
@@ -16,7 +16,7 @@ module Steep
16
16
  args << Builtin.any_type
17
17
  end
18
18
  end
19
- arity == args.size or raise "Mulformed instance type: name=#{module_name}, args=#{args}"
19
+ arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}"
20
20
 
21
21
  Types::Name::Instance.new(name: module_name, args: args)
22
22
  end
@@ -28,7 +28,7 @@ module Steep
28
28
  def instance_type?(type, args: nil)
29
29
  if type.is_a?(Types::Name::Instance)
30
30
  if args
31
- arity == args.size or raise "Mulformed instance type: name=#{module_name}, args=#{args}"
31
+ arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}"
32
32
  type.name == module_name && type.args == args
33
33
  else
34
34
  type.name == module_name && type.args.size == arity
@@ -9,6 +9,12 @@ module Steep
9
9
 
10
10
  attr_reader :type_interface_cache
11
11
 
12
+ def inspect
13
+ s = "#<%s:%#018x " % [self.class, object_id]
14
+ s << "@definition_builder=#<%s:%#018x>" % [definition_builder.class, definition_builder.object_id]
15
+ s + ">"
16
+ end
17
+
12
18
  def initialize(builder:)
13
19
  @definition_builder = builder
14
20
 
@@ -282,8 +288,6 @@ module Steep
282
288
  fvs = self_type.free_variables()
283
289
 
284
290
  type_params = []
285
- alpha_vars = []
286
- alpha_types = []
287
291
 
288
292
  conflicting_names = method_type.type_params.each.with_object([]) do |param, names|
289
293
  names << params.name if fvs.include?(param.name)
@@ -395,7 +399,7 @@ module Steep
395
399
  when AST::Types::Boolean
396
400
  [type, type]
397
401
  else
398
- [type, nil]
402
+ [type, AST::Types::Bot.new()]
399
403
  end
400
404
  end
401
405
 
@@ -45,6 +45,8 @@ module Steep
45
45
  end
46
46
  end
47
47
 
48
+ include Helper::ChildrenLevel
49
+
48
50
  def level
49
51
  children = type.params.each_type.to_a + [type.return_type]
50
52
  if block
data/lib/steep/cli.rb CHANGED
@@ -271,7 +271,9 @@ if type "rbenv" > /dev/null 2>&1; then
271
271
  STEEP="rbenv exec ${STEEP}"
272
272
  else
273
273
  if type "rvm" > /dev/null 2>&1; then
274
- STEEP="rvm ${ROOT_DIR} do ${STEEP}"
274
+ if [ -e ${ROOT_DIR}/.ruby-version ]; then
275
+ STEEP="rvm ${ROOT_DIR} do ${STEEP}"
276
+ fi
275
277
  fi
276
278
  fi
277
279
 
@@ -7,7 +7,7 @@ module Steep
7
7
  attr_reader :node
8
8
  attr_reader :location
9
9
 
10
- def initialize(node:, location: node.location.expression)
10
+ def initialize(node:, location: node&.location&.expression)
11
11
  @node = node
12
12
  @location = location
13
13
  end
@@ -71,6 +71,8 @@ module Steep
71
71
  end
72
72
 
73
73
  def header_line
74
+ node = node() or raise
75
+
74
76
  element = case node.type
75
77
  when :ivasgn, :lvasgn, :gvasgn, :cvasgn
76
78
  "a variable"
@@ -296,7 +298,7 @@ module Steep
296
298
  attr_reader :method_type
297
299
 
298
300
  def initialize(node:, method_type:)
299
- super(node: node, location: node.loc.selector)
301
+ super(node: node, location: (node.type == :super || node.type == :zsuper) ? node.loc.keyword : node.loc.selector)
300
302
  @method_type = method_type
301
303
  end
302
304
 
@@ -387,6 +389,7 @@ module Steep
387
389
 
388
390
  class UnexpectedJumpValue < Base
389
391
  def header_line
392
+ node = node() or raise
390
393
  "The value given to #{node.type} will be ignored"
391
394
  end
392
395
  end
@@ -452,7 +455,7 @@ module Steep
452
455
  super(node: node)
453
456
  @interface_method = interface_method
454
457
  @annotation_method = annotation_method
455
- @result = relation
458
+ @result = result
456
459
  end
457
460
  end
458
461
 
@@ -578,6 +581,32 @@ module Steep
578
581
 
579
582
  autoload :UnknownConstantAssigned, "steep/diagnostic/deprecated/unknown_constant_assigned"
580
583
 
584
+ class UnknownInstanceVariable < Base
585
+ attr_reader :name
586
+
587
+ def initialize(node:, name:)
588
+ super(node: node, location: node.loc.name)
589
+ @name = name
590
+ end
591
+
592
+ def header_line
593
+ "Cannot find the declaration of instance variable: `#{name}`"
594
+ end
595
+ end
596
+
597
+ class UnknownGlobalVariable < Base
598
+ attr_reader :name
599
+
600
+ def initialize(node:, name:)
601
+ super(node: node, location: node.loc.name)
602
+ @name = name
603
+ end
604
+
605
+ def header_line
606
+ "Cannot find the declaration of global variable: `#{name}`"
607
+ end
608
+ end
609
+
581
610
  class FallbackAny < Base
582
611
  def initialize(node:)
583
612
  super(node: node)
@@ -617,7 +646,7 @@ module Steep
617
646
  attr_reader :relation
618
647
 
619
648
  def initialize(node:, var_name:, result:, relation:)
620
- super(node: node)
649
+ super(node: node, location: node.location.expression)
621
650
  @var_name = var_name
622
651
  @result = result
623
652
  @relation = relation
@@ -688,6 +717,22 @@ module Steep
688
717
  end
689
718
  end
690
719
 
720
+ class MultipleAssignmentConversionError < Base
721
+ attr_reader :original_type, :returned_type
722
+
723
+ def initialize(node:, original_type:, returned_type:)
724
+ super(node: node)
725
+
726
+ @node = node
727
+ @original_type = original_type
728
+ @returned_type = returned_type
729
+ end
730
+
731
+ def header_line
732
+ "Cannot convert `#{original_type}` to Array or tuple (`#to_ary` returns `#{returned_type}`)"
733
+ end
734
+ end
735
+
691
736
  class UnsupportedSyntax < Base
692
737
  attr_reader :message
693
738
 
@@ -700,6 +745,7 @@ module Steep
700
745
  if message
701
746
  message
702
747
  else
748
+ node = node() or raise
703
749
  "Syntax `#{node.type}` is not supported in Steep"
704
750
  end
705
751
  end
@@ -264,6 +264,24 @@ module Steep
264
264
  end
265
265
  end
266
266
 
267
+ class ClassVariableDuplicationError < Base
268
+ attr_reader :class_name
269
+ attr_reader :other_class_name
270
+ attr_reader :variable_name
271
+
272
+ def initialize(class_name:, other_class_name:, variable_name:, location:)
273
+ super(location: location)
274
+
275
+ @class_name = class_name
276
+ @other_class_name = other_class_name
277
+ @variable_name = variable_name
278
+ end
279
+
280
+ def header_line
281
+ "Class variable definition `#{variable_name}` in `#{class_name}` may be overtaken by `#{other_class_name}`"
282
+ end
283
+ end
284
+
267
285
  class InstanceVariableTypeError < Base
268
286
  attr_reader :name
269
287
  attr_reader :variable
@@ -139,7 +139,7 @@ module Steep
139
139
  missing_count = 0
140
140
 
141
141
  ns = notifications.each.with_object({}) do |notification, hash|
142
- path = project.relative_path(Pathname(URI.parse(notification[:uri]).path))
142
+ path = project.relative_path(Steep::PathHelper.to_pathname(notification[:uri]))
143
143
  hash[path] = notification[:diagnostics]
144
144
  end
145
145
 
@@ -186,7 +186,7 @@ module Steep
186
186
  end
187
187
 
188
188
  ns = notifications.each.with_object({}) do |notification, hash|
189
- path = project.relative_path(Pathname(URI.parse(notification[:uri]).path))
189
+ path = project.relative_path(Steep::PathHelper.to_pathname(notification[:uri]))
190
190
  hash[path] = notification[:diagnostics]
191
191
  end
192
192
 
@@ -215,7 +215,7 @@ module Steep
215
215
  total = errors.sum {|notification| notification[:diagnostics].size }
216
216
 
217
217
  errors.each do |notification|
218
- path = Pathname(URI.parse(notification[:uri]).path)
218
+ path = Steep::PathHelper.to_pathname(notification[:uri])
219
219
  buffer = RBS::Buffer.new(name: project.relative_path(path), content: path.read)
220
220
  printer = DiagnosticPrinter.new(buffer: buffer, stdout: stdout)
221
221
 
@@ -79,7 +79,7 @@ module Steep
79
79
  file_paths = Set.new(dirs.select(&:file?).map(&:realpath))
80
80
 
81
81
  listener = Listen.to(*watch_paths.map(&:to_s)) do |modified, added, removed|
82
- stdout.puts Rainbow("🔬 Type checking updated files...").bold
82
+ stdout.print Rainbow("🔬 Type checking updated files...").bold
83
83
 
84
84
  version = Time.now.to_i
85
85
  Steep.logger.tagged "watch" do
@@ -112,6 +112,8 @@ module Steep
112
112
  end
113
113
 
114
114
  client_writer.write(method: "$/typecheck", params: { guid: nil })
115
+
116
+ stdout.puts Rainbow("done!").bold
115
117
  end.tap(&:start)
116
118
 
117
119
  begin
@@ -1,24 +1,30 @@
1
1
  module Steep
2
- InstanceMethodName = Struct.new(:type_name, :method_name, keyword_init: true) do
2
+ InstanceMethodName = _ = Struct.new(:type_name, :method_name, keyword_init: true) do
3
+ # @implements InstanceMethodName
3
4
  def to_s
4
5
  "#{type_name}##{method_name}"
5
6
  end
6
7
  end
7
8
 
8
- SingletonMethodName = Struct.new(:type_name, :method_name, keyword_init: true) do
9
+ SingletonMethodName = _ = Struct.new(:type_name, :method_name, keyword_init: true) do
10
+ # @implements SingletonMethodName
9
11
  def to_s
10
12
  "#{type_name}.#{method_name}"
11
13
  end
12
14
  end
13
15
 
14
- module ::Kernel
16
+ class ::Object
15
17
  def MethodName(string)
16
18
  case string
17
19
  when /#/
18
20
  type_name, method_name = string.split(/#/, 2)
21
+ type_name or raise
22
+ method_name or raise
19
23
  InstanceMethodName.new(type_name: TypeName(type_name), method_name: method_name.to_sym)
20
24
  when /\./
21
25
  type_name, method_name = string.split(/\./, 2)
26
+ type_name or raise
27
+ method_name or raise
22
28
  SingletonMethodName.new(type_name: TypeName(type_name), method_name: method_name.to_sym)
23
29
  else
24
30
  raise "Unexpected method name: #{string}"