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

NoMethodError: undefined method `required_positionals' #2025

Open
aaronmallen opened this issue Sep 22, 2024 · 1 comment
Open

NoMethodError: undefined method `required_positionals' #2025

aaronmallen opened this issue Sep 22, 2024 · 1 comment

Comments

@aaronmallen
Copy link

aaronmallen commented Sep 22, 2024

Hi, I am running into an issue with blocks in rbs. It should be noted that this spec passes with rbs disabled.

rbs 3.5.3

given the following RSpec spec:

describe '.parameter' do
  it 'adds a parameter to the parameter set' do
    described_class.parameter(:test) do
      desc 'A test parameter'
    end

    expect(described_class.parameters.test).to be_an_instance_of(Domainic::Type::Constraint::Parameter)
      .and(have_attributes(name: :test, description: 'A test parameter'))
  end
end

and the following signatures:

class Base
  class << self
    def parameter(parameter_name, &)
      parameter_builder.define(parameter_name, &).build!
    end
    
    private
  
    def parameter_builder
      @parameter_builder ||= DSL::ParameterBuilder.new(self)
    end
  end
end
class Base
 def self.parameter: (::String | Symbol parameter_name) { (?) -> DSL::ParameterBuilder } -> void
 
 private

 def self.parameter_builder: -> DSL::ParameterBuilder
end
module DSL
  class ParameterBuilder
    def define(parameter_name, &)
      @current_parameter = @data[parameter_name.to_sym] ||=
        PARAMETER_DEFAULTS.transform_values(&:dup).merge(name: parameter_name.to_sym)
      instance_exec(&) if block_given?
      self
    end

    def description(description_string)
      raise ArgumentError, 'No parameter is currently being defined' if @current_parameter.nil?

      @current_parameter[:description] = description_string
      self
    end
    alias desc description
  end
end
module DSL
 class ParameterBuilder
   def define: (::String | ::Symbol parameter_name) { (?) -> self } -> self
   def description: (::String description_string) -> self
   alias desc description
 end
end

I get:

NoMethodError: undefined method `required_positionals' for #<RBS::Types::UntypedFunction:0x0000000110c3fe68 @return_type=#<RBS::Types::ClassInstance:0x0000000110c3ff30 @name=#<RBS::TypeName:0x0000000110c12030 @namespace=#<RBS::Namespace:0x0000000110c12080 @path=[:Domainic, :Type, :DSL], @absolute=true, @parent=#<RBS::Namespace:0x0000000110c11fb8 @path=[:Domainic, :Type], @absolute=true, @parent=#<RBS::Namespace:0x0000000110c11ec8 @path=[:Domainic], @absolute=true, @parent=#<RBS::Namespace:0x0000000110c11dd8 @path=[], @absolute=true>>>>, @name=:ParameterBuilder, @kind=:class>, @args=[], @location=#<RBS::Location:11700 buffer=domainic-type/sig/domainic/type/constraint/base/base.rbs, start=15:72, pos=369...390, children=name,?args source="DSL::ParameterBuilder">>>

  0) Domainic::Type::Constraint::Base.parameter adds a parameter to the parameter set
     Failure/Error:
       described_class.parameter(:test) do
         desc 'A test parameter'
       end

     NoMethodError:
       undefined method `required_positionals' for #<RBS::Types::UntypedFunction:0x0000000110c3fe68 @return_type=#<RBS::Types::ClassInstance:0x0000000110c3ff30 @name=#<RBS::TypeName:0x0000000110c12030 @namespace=#<RBS::Namespace:0x0000000110c12080 @path=[:Domainic, :Type, :DSL], @absolute=true, @parent=#<RBS::Namespace:0x0000000110c11fb8 @path=[:Domainic, :Type], @absolute=true, @parent=#<RBS::Namespace:0x0000000110c11ec8 @path=[:Domainic], @absolute=true, @parent=#<RBS::Namespace:0x0000000110c11dd8 @path=[], @absolute=true>>>>, @name=:ParameterBuilder, @kind=:class>, @args=[], @location=#<RBS::Location:11700 buffer=domainic-type/sig/domainic/type/constraint/base/base.rbs, start=15:72, pos=369...390, children=name,?args source="DSL::ParameterBuilder">>>
     # ./domainic-type/spec/domainic/type/constraint/base_spec.rb:11:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `desc' for #<RSpec::ExampleGroups::DomainicTypeConstraintBase::Parameter "adds a parameter to the parameter set" (./domainic-type/spec/domainic/type/constraint/base_spec.rb:10)>
     #   ./domainic-type/spec/domainic/type/constraint/base_spec.rb:12:in `block (4 levels) in <top (required)>'

Additionally the recommended annotation to skip tests does not fix the issue:

%a{rbs:test:skip} def self.parameter: (::String | Symbol parameter_name) { (?) -> DSL::ParameterBuilder } -> void
@miharekar
Copy link

Related issue on Ruby LSP which seems to be caused because of this: Shopify/ruby-lsp#2630

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

No branches or pull requests

2 participants