Shopify / Shopify/tapioca

Tapioca automatically converts nested style to compact style, causing 'Unable to resolve constant $class' error in RBI

Open
#1,861 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
873
Forks
164
Avg merge
4d 27m
Merged PRs (30d)
9

Description

sorbet version: 0.5.11332
tapioca version: 0.13.1
ruby version: 3.2.2

I encountered an issue when using Tapioca to generate RBI files for a gem dependency. The generated RBI file contains an Unable to resolve constant $class error.

Here's a minimal reproduction of the issue:

In repo X, I have the following files:
lib/x.rb

module X
  class Foo
  end

  class Bar
    def foo
      Foo.new
    end
  end
end

rbi/defs.rbi

# typed: strong

module X
  class Foo
  end

  class Bar
    sig { returns(Foo) }
    def foo
    end
  end
end

In repo Y, which depends on the gem from repo X, I have the following files:
Gemfile

gem "x"

After running bin/tapioca gem, the generated RBI file at sorbet/rbi/gems/x.rbi looks like this:

module X; end

class X::Foo
end

class X::Bar
  sig { returns(Foo) } # Unable to resolve constant `Foo`
  def foo
  end
end

Suspect file: pipeline.rb on GitHub

Contributor guide

No contributing guide indexed for this repository

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 with the minimal reproduction in the issue and run bin/tapioca gem to observe the generated sorbet/rbi/gems/x.rbi. Read lib/tapioca/gem/pipeline.rb, the suspected entry point, and trace how nested declarations become compact style. Done means the generated RBI no longer reports an unresolved Foo constant for X::Bar#foo.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.