Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

steepによる型チェックを修正してCIに組み込んだ #63

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

willnet
Copy link
Owner

@willnet willnet commented Jan 17, 2024

lib/gimei.rb:44:13: [error] Unexpected positional argument
│ Diagnostic ID: Ruby::UnexpectedPositionalArgument
│
└         name(gender).public_send(method_name)
               ~~~~~~

lib/gimei/name.rb:19:12: [error] Unexpected positional argument
│ Diagnostic ID: Ruby::UnexpectedPositionalArgument
│
└         new(gender).public_send(method_name)
              ~~~~~~
  • 次の2つのエラーは特異クラスにextend Forwardableする方法が現状ないため無視するようにした

lib/gimei.rb:27:4: [error] Type `singleton(::Class)` does not have method `def_delegators`
│ Diagnostic ID: Ruby::NoMethod
│
└     def_delegators 'Gimei::Name', :male, :female
      ~~~~~~~~~~~~~~

lib/gimei.rb:28:4: [error] Type `singleton(::Class)` does not have method `def_delegators`
│ Diagnostic ID: Ruby::NoMethod
│
└     def_delegators :address, :prefecture, :city, :town
      ~~~~~~~~~~~~~~
  • Gimei.names@namesはsteepに期待通りに解釈させる方法が見つからなかったのでひとまずuntypedのままにしておく

- `Gimei.addresses`の戻り値の型がおかしかったので直した
- Romajiの型がないので必要なものだけ定義した
- Array#sampleの戻り値にnilが含まれるためにエラーになっていたのをtype assertionを利用して解決した
  - ref: [steep/guides/src/nil-optional/nil-optional.md at master · soutaro/steep](https://github.com/soutaro/steep/blob/master/guides/src/nil-optional/nil-optional.md#handling-unwanted-nils)

- 次の2つのエラーは [`steep check` uses wrong context for `#define_method` in a singleton · Issue #380 · soutaro/steep](https://github.com/soutaro/steep/issues/380)にあるように、steepが特異クラスにおけるdefine_methodのブロックコンテキストを誤って解釈していることが原因と思われる。
  - 実装側を変更することで対応した
  - 型のために実装を変えるのはあまりやりたくはないのだけど、define_methodよりclass_evalのほうが速いので許容した

```
lib/gimei.rb:44:13: [error] Unexpected positional argument
│ Diagnostic ID: Ruby::UnexpectedPositionalArgument
│
└         name(gender).public_send(method_name)
               ~~~~~~

lib/gimei/name.rb:19:12: [error] Unexpected positional argument
│ Diagnostic ID: Ruby::UnexpectedPositionalArgument
│
└         new(gender).public_send(method_name)
              ~~~~~~
```

- 次の2つのエラーは特異クラスに`extend Forwardable`する方法が現状ないため無視するようにした

```

lib/gimei.rb:27:4: [error] Type `singleton(::Class)` does not have method `def_delegators`
│ Diagnostic ID: Ruby::NoMethod
│
└     def_delegators 'Gimei::Name', :male, :female
      ~~~~~~~~~~~~~~

lib/gimei.rb:28:4: [error] Type `singleton(::Class)` does not have method `def_delegators`
│ Diagnostic ID: Ruby::NoMethod
│
└     def_delegators :address, :prefecture, :city, :town
      ~~~~~~~~~~~~~~
```

- `Gimei.names`と`@names`はsteepに期待通りに解釈させる方法が見つからなかったのでひとまずuntypedのままにしておく
@coveralls
Copy link

coveralls commented Jan 17, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling 05683e8 on fix-type
into f4c48a1 on main.

現時点で最新のsteepはRuby3.0以上をサポートしている( https://rubygems.org/gems/steep/versions/1.6.0 )。

よって現在gimeiがサポートしているRubyのバージョンのうち、3.0未満のRubyではsteepが実行できない。

そもそもsteepによる型チェックはRubyのバージョンに依存するものはないはずなので、3.3だけで型チェックを実行するようにする。
@willnet willnet merged commit a685912 into main Jan 20, 2024
12 checks passed
@willnet willnet deleted the fix-type branch January 20, 2024 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants