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

Add example showing load_iseq interaction #7684

Draft
wants to merge 2 commits into
base: jez-custom-t-must-error
Choose a base branch
from

Conversation

jez
Copy link
Collaborator

@jez jez commented Feb 10, 2024

Motivation

❯ cd gems/sorbet-runtime
❯ ./run.sh
-- before require --
-- forcing LAZY_CONSTANT! --
LAZY_CONSTANT=0
-- before Example.main --
/Users/jez/stripe/sorbet/gems/sorbet-runtime/lib/types/_types.rb:222:in `must': Passed `nil` into T.must (T::MustTypeError)

    T.must(nil)
           ^^^
        from /Users/jez/stripe/sorbet/gems/sorbet-runtime/example_untransformed.rb:5:in `main'
        from entry.rb:20:in `<main>'


^unpatched ---------- patched:


-- before require --
-- transformed_src for path=/Users/jez/stripe/sorbet/gems/sorbet-runtime/example_untransformed.rb --
module Example
  autoload :LAZY_CONSTANT, '/Users/jez/stripe/sorbet/gems/sorbet-runtime/example_transformed.rb'

  def self.main
    T.must(nil)
  end
end
-----
-- forcing LAZY_CONSTANT! --
LAZY_CONSTANT=0
-- before Example.main --
/Users/jez/stripe/sorbet/gems/sorbet-runtime/lib/types/_types.rb:222:in `must': Passed `nil` into T.must (T::MustTypeError)

    T.must(nil)
    ^
        from /Users/jez/stripe/sorbet/gems/sorbet-runtime/example_untransformed.rb:5:in `main'
        from entry.rb:20:in `<main>'

Test plan

See included automated tests.

    ❯ bundle exec ruby dne_entry.rb; echo $'\n\n^unpatched ---------- patched:\n\n'; PATCH_LOAD_ISEQ=1 bundle exec ruby dne_entry.rb
    -- before require --
    -- forcing LAZY_CONSTANT! --
    LAZY_CONSTANT=0
    -- before DNE.main --
    /Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_untransformed.rb:5:in `main': uninitialized constant Integer::DoesNotExist (NameError)

        Integer::DoesNotExist
               ^^^^^^^^^^^^^^
            from dne_entry.rb:20:in `<main>'

    ^unpatched ---------- patched:

    -- before require --
    -- transformed_src for path=/Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_untransformed.rb --
    module DNE
      autoload :LAZY_CONSTANT, '/Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_transformed.rb'

      def self.main
        Integer::DoesNotExist
      end
    end
    -----
    -- forcing LAZY_CONSTANT! --
    LAZY_CONSTANT=0
    -- before DNE.main --
    /Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_untransformed.rb:5:in `main': uninitialized constant Integer::DoesNotExist (NameError)
            from dne_entry.rb:20:in `<main>'
@jez
Copy link
Collaborator Author

jez commented Feb 10, 2024

Interestingly, this does not affect the monkey patch for NameError, which seems to turn itself off in this case:

❯ bundle exec ruby dne_entry.rb; echo $'\n\n^unpatched ---------- patched:\n\n'; PATCH_LOAD_ISEQ=1 bundle exec ruby dne_entry.rb
-- before require --
-- forcing LAZY_CONSTANT! --
LAZY_CONSTANT=0
-- before DNE.main --
/Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_untransformed.rb:5:in `main': uninitialized constant Integer::DoesNotExist (NameError)

    Integer::DoesNotExist
           ^^^^^^^^^^^^^^
        from dne_entry.rb:20:in `<main>'


^unpatched ---------- patched:


-- before require --
-- transformed_src for path=/Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_untransformed.rb --
module DNE
  autoload :LAZY_CONSTANT, '/Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_transformed.rb'

  def self.main
    Integer::DoesNotExist
  end
end
-----
-- forcing LAZY_CONSTANT! --
LAZY_CONSTANT=0
-- before DNE.main --
/Users/jez/stripe/sorbet/gems/sorbet-runtime/dne_untransformed.rb:5:in `main': uninitialized constant Integer::DoesNotExist (NameError)
        from dne_entry.rb:20:in `<main>'

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

Successfully merging this pull request may close these issues.

None yet

1 participant