Skip to content

Cannot use @!scope class on an attribute defined by attr_* #1582

Open
@UlyssesZh

Description

@UlyssesZh

If I add @!scope class for a attr_* call (such as attr_reader :test), there is an error.

Discussion context: #1581.

Steps to reproduce

Write these to lib/test.rb:

# A test class.
class Test

  # @!scope class
  # A test attribute.
  attr_reader :test
end

Then run yard doc --debug.

Actual Output

[debug]: Parsing ["{lib,app}/**/*.rb", "ext/**/*.{c,cc,cxx,cpp,rb}"] with `ruby` parser
[debug]: Parsing lib/test.rb                                                                   
[debug]: Serializing to .yardoc/objects/root.dat
[debug]: Re-generating object ...                                                                                                                                                             
[debug]: Re-generating object Test...                                                                                                                                                         
[debug]: Generating asset js/jquery.js                                                                                                                                                        
[debug]: Serializing to doc/js/jquery.js                                                                                                                                                      
[debug]: Generating asset js/app.js                                                                                                                                                           
[debug]: Serializing to doc/js/app.js                                                                                                                                                         
[debug]: Generating asset js/full_list.js
[debug]: Serializing to doc/js/full_list.js
[debug]: Generating asset css/style.css
[debug]: Serializing to doc/css/style.css
[debug]: Generating asset css/common.css
[debug]: Serializing to doc/css/common.css
[debug]: Generating asset css/full_list.css
[debug]: Serializing to doc/css/full_list.css
[debug]: Generating asset class_list.html
[debug]: Serializing to doc/class_list.html
[debug]: Generating asset method_list.html
[debug]: Serializing to doc/method_list.html
[debug]: Generating asset file_list.html
[debug]: Serializing to doc/file_list.html
[debug]: Generating asset frames.html
[debug]: Serializing to doc/frames.html
[debug]: Serializing to doc/index.html
[debug]: Serializing to doc/_index.html
[debug]: Serializing to doc/top-level-namespace.html
[error]: Exception occurred while generating 'Test.html'
[error]: NoMethodError: undefined method `[]' for nil
[error]: Stack trace:
        /home/ulysses/.local/share/gem/ruby/3.3.0/gems/yard-0.9.37/templates/default/module/html/attribute_details.erb:8:in `block (2 levels) in _erb_cache_24'
        /home/ulysses/.local/share/gem/ruby/3.3.0/gems/yard-0.9.37/templates/default/module/html/attribute_details.erb:6:in `each'
        /home/ulysses/.local/share/gem/ruby/3.3.0/gems/yard-0.9.37/templates/default/module/html/attribute_details.erb:6:in `each_with_index'
        /home/ulysses/.local/share/gem/ruby/3.3.0/gems/yard-0.9.37/templates/default/module/html/attribute_details.erb:6:in `block in _erb_cache_24'
        /home/ulysses/.local/share/gem/ruby/3.3.0/gems/yard-0.9.37/templates/default/module/setup.rb:155:in `block in scopes'
        /home/ulysses/.local/share/gem/ruby/3.3.0/gems/yard-0.9.37/templates/default/module/setup.rb:153:in `each'

Files:           1
Modules:         0 (    0 undocumented)
Classes:         1 (    0 undocumented)
Constants:       0 (    0 undocumented)
Attributes:      0 (    0 undocumented)
Methods:         1 (    0 undocumented)
 100.00% documented

Expected Output

Should be equivalent to what this would do:

# A test class.
class Test

  # @!scope class
  # @!attribute [r] test
  # A test attribute.
end

Environment details:

  • OS: NixOS 24.05
  • Ruby version (ruby -v): 3.3.4
  • YARD version (yard -v): 0.9.37

I have read the Contributing Guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions