rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Singleton does not have method `instance`

Open mschoenlaub opened this issue 2 years ago • 2 comments

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.

mschoenlaub avatar Sep 04 '23 19:09 mschoenlaub

I'm also running into this, and I can fix it by adding the following additional signature:

module A
  module Example
    class TestClass
      def self.instance: () -> singleton(A::Example::TestClass)
    end
  end
end

But then I get a new error:

Type `singleton(::A::Example::TestClass)` does not have method `example`

nogweii avatar Oct 26 '23 07:10 nogweii