個人的な興味で RBS を一度調べたことがあって,今回もその辺りを後で確認していく流れ
$ rbs subtract
ignore するのが欲しかったので,subract
がポイントなのかも.
試してみる
$ ruby -v
ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-linux]
$ gh repo clone https://github.com/r7kamura/mem
$ cd mem
$ git diff
diff --git a/mem.gemspec b/mem.gemspec
index 2d578ae..eb8c9b8 100644
--- a/mem.gemspec
+++ b/mem.gemspec
@@ -18,5 +18,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
- spec.add_development_dependency "rspec", "2.14.1"
+ spec.add_development_dependency "rspec"
+ spec.add_development_dependency "typeprof"
+ spec.add_development_dependency "steep"
end
$ bundle install
$ typeprof lib/mem.rb lib/mem/core_ext.rb lib/mem/version.rb spec/mem_spec.rb spec/spec_helper.rb > sig/mem.rbs
$ cat Steepfile
target :lib do
signature "sig"
check "lib"
end
$ steep check
# Type checking files:
........................................F......................[Steep 1.4.0] [typecheck:typecheck@1] [background] Unexpected error: #<RBS::RecursiveAncestorError: /usr/local/bundle/gems/rbs-3.1.0/core/object.rbs:108:
0...1075:3: Detected recursive ancestors: ::Object < ::Mem < ::Object>
(snip)
Recursive らしい
sig/mem.rbs
# TypeProf 0.21.7
# Classes
class Object
extend Mem::ClassMethods
include Mem
private
def a: (untyped value) -> [untyped, untyped]
| -> nil
def b: (untyped value) -> [untyped, untyped]
| (untyped value) -> [untyped, untyped]
| -> nil
def c: -> String
| -> nil
def a!: (untyped value) -> [untyped, untyped]
end
module Mem
VERSION: String
@memoized_table: Hash[untyped, untyped]
def self.included: (singleton(Object) base) -> singleton(Object)
def has_memoized?: (untyped key) -> bool
def memoize: (untyped key, untyped value) -> untyped
def memoized: (untyped key) -> nil
def memoized_table: -> Hash[untyped, untyped]
def unmemoize: (untyped key) -> nil
module ClassMethods
def memoize: (untyped method_name) -> nil
end
end
-
Object include Mem
が怪しい.
sig-ignore/hand-written.rbs
class Object
include Mem
end
$ rbs subtract -w sig/mem.rbs sig-ignore/hand-writte.rbs
この時点で,include Mem
が無くなっていることは確認した
$ steep check
# Type checking files:
..............................................................................F.......
lib/mem.rb:32:13: [error] Type `(::Object & ::Mem::ClassMethods)` does not have method `protected_instance_methods`
(snip)
結果が変わったので,使えているのはわかった.
NOTE
最初,hand-written.rbs を 同じディレクトリに入れていてハマっていた.
考えればあたりまえだった.
余談
- 全然関係ないけど,Rouge が RBS 対応して欲しい.