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

rewriter::Flatten pulls sig call out of method body even if it's not actually a method signature #7768

Open
jez opened this issue Mar 15, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@jez
Copy link
Collaborator

jez commented Mar 15, 2024

Input

→ View on sorbet.run

# typed: true

class A
  extend T::Sig

  def foo(x)
    x.sig { void }
  end
end

Observed output

class <emptyTree><<C <root>>> < (::<todo sym>)
  class <emptyTree>::<C A><<C <todo sym>>> < (::<todo sym>)
    def foo<<todo method>>(x, &<blk>)
      nil
    end

    x.sig() do ||
      <self>.void()
    end

    <self>.extend(<emptyTree>::<C T>::<C Sig>)

    <runtime method definition of foo>
  end
end
editor.rb:7: Method sig does not exist on NilClass https://srb.help/7003
     7 |    x.sig { void }
              ^^^
  Got NilClass originating from:
    editor.rb:3: Possibly uninitialized (NilClass) in:
     3 |class A
     4 |  extend T::Sig
     5 |
     6 |  def foo(x)
     7 |    x.sig { void }
     8 |  end
     9 |end

editor.rb:7: Method void does not exist on T.class_of(A) https://srb.help/7003
     7 |    x.sig { void }
                    ^^^^
  Did you mean load? Use -a to autocorrect
    editor.rb:7: Replace with load
     7 |    x.sig { void }
                    ^^^^
    https://github.com/sorbet/sorbet/tree/master/rbi/core/kernel.rbi#L1664: Defined here
    1664 |  def load(filename, arg0=T.unsafe(nil)); end
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 2

Expected behavior

Sorbet pulls the x.sig { void } call out to the top level of the class definition in an attempt to flatten all nested method definitions. That's not what should have happened—this method call doesn't actually match what a sig would look like, nor is there a call to a method immediately after this sig call.


@jez jez added bug Something isn't working good first issue Good for newcomers labels Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant