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

runtime: Top-level extend T::Sig is not supported #923

Closed
AaronC81 opened this issue Jun 20, 2019 · 3 comments
Closed

runtime: Top-level extend T::Sig is not supported #923

AaronC81 opened this issue Jun 20, 2019 · 3 comments
Labels
bug Something isn't working runtime Related to the sorbet-runtime gem

Comments

@AaronC81
Copy link
Contributor

Input

→ View on sorbet.run

# typed: strong
require 'sorbet-runtime'
extend T::Sig

sig { params(a: Numeric, b: Numeric).returns Numeric }
def division(a, b)
    a / b
end

puts division(4, 2)

Observed output

No errors! Great job.

The issue is not with the typechecking itself, but instead with sorbet-runtime. Executing this file results in:

Traceback (most recent call last):
        3: from main.rb:5:in `<main>'
        2: from /var/lib/gems/2.5.0/gems/sorbet-runtime-0.4.4254/lib/types/sig.rb:24:in `sig'
        1: from /var/lib/gems/2.5.0/gems/sorbet-runtime-0.4.4254/lib/types/private/methods/_methods.rb:16:in `declare_sig'
/var/lib/gems/2.5.0/gems/sorbet-runtime-0.4.4254/lib/types/private/methods/_methods.rb:307:in `install_hooks': undefined method `singleton_class?' for main:Object (NoMethodError)
Did you mean?  singleton_class

(Note that line 5 is the sig line.)

I am using "Ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]", on Ubuntu 18.04. The behaviour does not change whether I execute the file using Bundler (bundle exec ruby main.rb) or just with the standard Ruby interpreter directly (ruby main.rb).

Expected behavior

I would expect that the file executes successfully and prints 2.

@AaronC81 AaronC81 added bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team labels Jun 20, 2019
@AaronC81 AaronC81 changed the title undefined method "singleton_class?" for main:Object Bug with undefined method "singleton_class?" when executing file Jun 20, 2019
@AaronC81
Copy link
Contributor Author

AaronC81 commented Jun 20, 2019

It appears that the issue only arises when the method definitions are in the top-level of the file (i.e. not inside a module). This works fine:

# typed: strong
require 'sorbet-runtime'

module A
    extend T::Sig

    sig { params(a: Numeric, b: Numeric).returns Numeric }
    def self.division(a, b)
        a / b
    end
end

puts A.division(4, 2)

@AaronC81 AaronC81 changed the title Bug with undefined method "singleton_class?" when executing file Bug with undefined method "singleton_class?" when executing file with top-level methods Jun 20, 2019
@DarkDimius DarkDimius removed the unconfirmed This issue has not yet been confirmed by the Sorbet team label Jun 20, 2019
@jez
Copy link
Collaborator

jez commented Jun 23, 2019

This is a duplicate of #199 but I like the examples and extra information in this issue, so I'm closing the other one.

@jez jez changed the title Bug with undefined method "singleton_class?" when executing file with top-level methods runtime: Top-level extend T::Sig is not supported Aug 23, 2019
@Morriar Morriar added the runtime Related to the sorbet-runtime gem label Aug 19, 2020
@jez
Copy link
Collaborator

jez commented Dec 21, 2020

Fixed in #3491

@jez jez closed this as completed Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working runtime Related to the sorbet-runtime gem
Projects
None yet
Development

No branches or pull requests

4 participants