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

@implements in blocks #338

Closed
soutaro opened this issue Mar 16, 2021 · 1 comment · Fixed by #355, #364 or #366
Closed

@implements in blocks #338

soutaro opened this issue Mar 16, 2021 · 1 comment · Fixed by #355, #364 or #366

Comments

@soutaro
Copy link
Owner

soutaro commented Mar 16, 2021

Some methods including #instance_eval change the value of self inside the given block. @type self annotation is for this case, but it doesn't work for method definitions. We typically see this when we use Struct class.

ReadMessageJob = _ = Struct.new(:source, :message) do
  # @implements ReadMessageJob

  def request?
    message[:method] && message[:id]
  end
end

The problem is

  1. @implements annotations inside blocks are ignored.
  2. @type self: T and @type module: T are not for method definitions.

So, I'd like to extend @implements annotations to be placed inside blocks.

@soutaro
Copy link
Owner Author

soutaro commented Mar 28, 2021

Doesn't work for:

class Methods
  Definition = _ = Struct.new(:name, :type, :originals, :overloads, :accessibilities, keyword_init: true) do
    # @implements Definition

    def self.empty(name:, type:)
      new(type: type, name: name, originals: [], overloads: [], accessibilities: [])
    end
  end
end

The new call in self.empty is resolved to Methods.new. 💣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant