steep icon indicating copy to clipboard operation
steep copied to clipboard

Treat `present?` as a special method that guarantees the receiver is not nil

Open mtsmfm opened this issue 1 year ago • 3 comments

Fixes https://github.com/soutaro/steep/issues/472

The pull request https://github.com/soutaro/steep/pull/905 attempts to resolve the issue using annotations, but this PR resolves it by treating present? as a special method, similar to how Sorbet handles it https://github.com/sorbet/sorbet/blob/718bc64f895abeeff88f56efbc92a3554ffaa4f2/infer/environment.cc#L564-L579

mtsmfm avatar May 20 '24 15:05 mtsmfm

Thank you for opening this PR. I think there are two things to consider:

  1. It's not ReceiverIsNotNil. Introducing ReceiverIsPresent or something would be better. (And because the negation doesn't mean it's nil, the implementation should be revised.)
  2. I'm not very sure if we should have this implementation in Steep. It's not a part of Ruby. The semantics look like too complicated.

soutaro avatar Jun 07 '24 07:06 soutaro

Do we need steep-rails?

ksss avatar Jun 07 '24 07:06 ksss

We can support these non-Ruby methods by extending RBS types where we can directly write something like:

  def present?: () -> self is not blank

soutaro avatar Jun 07 '24 07:06 soutaro