ruby / ruby/rbs

relative lookup failing when subclass has the same name as eval'ed class

Open
#2,650 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

I have the following sig defined:

# resolver/resolver.rbs
module HTTPX
  module Resolver
    class Resolver
    end
  end
end

# resolver.rbs
module HTTPX
  module Resolver
    def self?.resolver_for: () -> singleton(Resolver::Resolver)
  end
end

runtime evaluation using runtime rbs/tester.rb fails though, because the parsed type for the method return is wrong, i.e. it evaluates to a RBS::Types::ClassSingleton instance with a namespace declaring @path=[:Resolver], which when evaluated to to_s, evaluates to Resolver::Resolver, instead of HTTPX::Resolver::Resolver.

I found two workarounds:

def self?.resolver_for: () -> singleton(HTTPX::Resolver::Resolver) #=> absolute namespace, bypasses issues
def self?.resolver_for: () -> singleton(Resolver) #=> resolves to class Resolver instead of module Resolver, which seems wrong

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the signatures in resolver/resolver.rbs and resolver.rbs using runtime rbs/tester.rb. Trace how the relative singleton type is evaluated in the HTTPX::Resolver context; done means it resolves to HTTPX::Resolver::Resolver rather than Resolver::Resolver.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.