8000 Fix self union type checking by marcotc · Pull Request #1467 · soutaro/steep · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix self union type checking #1467

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

Merged
merged 1 commit into from
Feb 28, 2025
Merged

Conversation

marcotc
Copy link
Contributor
@marcotc marcotc commented Jan 14, 2025

This fixes the case where a method can return either self or another value (e.g. -> (self | nil)).

Here's the concrete example: https://github.com/DataDog/dd-trace-rb/blob/5361e8e9a7092ca081ff0d5126daf8950bb2c792/lib/datadog/tracing/span_operation.rb#L202-L223

      def stop(stop_time = nil)
        return if stopped?

        now = Core::Utils::Time.now.utc

        start(stop_time || now) unless started?

        @end_time = stop_time || now
        @duration_end = stop_time.nil? ? duration_marker : nil

        events.after_stop.publish(self)

        self
      end

Currently this fails with:

Cannot allow method body have type `self` because declared as type `(self | nil)`
Diagnostic ID: Ruby::MethodBodyTypeMismatch

@ParadoxV5
Copy link
Contributor

Could be similar:

def example(x) = x
class Object
  def example: [X < top] (X) -> X?
end
# Type checking files:

.F

ruby.rb:1:4: [error] Cannot allow method body have type `X` because declared as type `(X | nil)`
│   X <: (X | nil)
│     top <: (X | nil)
│       top <: X
│
│ Diagnostic ID: Ruby::MethodBodyTypeMismatch
│
└ def example(x) = x
      ~~~~~~~

Copy link
Owner
@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

@soutaro soutaro added this to the Steep 1.10 milestone Feb 28, 2025
@soutaro soutaro merged commit 0b01e62 into soutaro:master Feb 28, 2025
17 checks passed
@soutaro soutaro added the Released The PR is already included in a published release label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released The PR is already included in a published release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0