ruby / ruby/rbs

Singleton does not have method `instance`

Open
#1,498 2 comments 3 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

Typechecking for singletons (the pattern) doesn't seem to work as expected.

E.g. given an rb file

# frozen_string_literal: true
require "singleton"

module A
  module Example
    class TestClass
      include Singleton
    end
  end
end

A::Example::TestClass.instance

and and RBS file:

module A
  module Example
    VERSION: String

    class TestClass
      include Singleton
    end
  end
end

steep complains about: Type singleton(::A::Example::TestClass) does not have method instance.

The simples possible Steepfile i could come up with for the repro case:

 target :lib do
    signature "sig"
    check "lib"
    library "singleton"
 end

Given that there are some moving parts involved but also there's still active development going on, I wonder whether this supposed to even work right now?

In the original project The class including Singleton also extends Forwardable and so i was somehow hoping that it's just some weirdness. But even in this simple repro case it just doesn't work as expected.

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

Start by running the supplied Ruby and RBS reproduction with the minimal Steepfile, focusing on the singleton library and include Singleton behavior. Done means the type checker recognizes A::Example::TestClass.instance without reporting that the singleton type lacks the method.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.