Closed mtasaka closed 8 months ago
I did some preliminary testing here and, although I wasn't able to confirm how this is connected to the commit linked, one thing is for certain: When calling P(:Testing)
in ruby 3.2.2, the returned class is an instance of YARD::CodeObjects::ClassObject
and it has 126 methods. tag
, which is defined in code_objects/base.rb:548
is among them.
Where as running this against 3.3.0 dev's latest commit, the object returned by P(:Testing)
has only 72 methods and it's an instance of YARD::CodeObjects::Proxy
.
I'm unsure how this is supposed to work, but given the docs for the P
method, seems to me that ruby 3.3.0 is returning the correct object, but it's weird
So, after more digging, and maybe dealing specifically with the issue at hand, the file parsed in the yield handler spec has invalid ruby syntax, as of the latest commit.
The tests in https://github.com/ruby/ruby/commit/b5e23d3e3b5ff2f5328aa43a2392ebe7c951a222 assert that simply writing yield
inside a class is invalid. Going by the assertions, we'd have to write:
class Testing
defined?(yield)
end
I did as much, but another error surfaced related to the locale spec. I'll open a PR with the change which could be modified to fix all failing specs as they appear.
So, I made a mistake. I think I might've edited the test file by accident, but indeed we didn't have yield
but yield x, y, x
. It's still invalid code according to the tests, if I understood it right.
~That being said, I've tested the specs using the latest 3.3.0 preview1 and they pass. I'm getting a failure still, however, but I think it's something on my end, because it fails on all ruby versions and it wasn't failing before. So maybe this issue won't be an issue?~
EDIT: Just confirmed that all specs pass with ruby 3.3.0 preview 1
So trying to shorten test spec file yield_handler_spec.rb
: https://github.com/lsegal/yard/blob/698b22cc2340230856ab17a25cfefa889f1c8289/spec/handlers/yield_handler_spec.rb as:
# frozen_string_literal: true
require File.dirname(__FILE__) + '/spec_helper'
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}YieldHandler" do
before(:all) { parse_file :yield_handler_001, __FILE__ }
it "only parses yield blocks in methods" do
expect(P(:Testing).tag(:yield)).to be nil
end
end
Then I see the following message:
YARD::Handlers::Ruby::YieldHandler
[warn]: Syntax error in `/builddir/build/build/yard-0.9.34/spec/handlers/examples/yield_handler_001.rb.txt`:(3,2): invalid yield
[warn]: ParserSyntaxError: syntax error in `/builddir/build/BUILD/yard-0.9.34/spec/handlers/examples/yield_handler_001.rb.txt`:(3,2): Invalid yield
[warn]: Stack trace:
/builddir/build/BUILD/yard-0.9.34/lib/yard/parser/ruby/ruby_parser.rb:607:in `on_parse_error'
/builddir/build/BUILD/yard-0.9.34/lib/yard/parser/ruby/ruby_parser.rb:56:in `parse'
/builddir/build/BUILD/yard-0.9.34/lib/yard/parser/ruby/ruby_parser.rb:56:in `parse'
/builddir/build/BUILD/yard-0.9.34/lib/yard/parser/ruby/ruby_parser.rb:17:in `parse'
/builddir/build/BUILD/yard-0.9.34/lib/yard/parser/source_parser.rb:442:in `parse'
/builddir/build/BUILD/yard-0.9.34/lib/yard/parser/source_parser.rb:46:in `block in parse'
So to make whole spec test suite successful, the following change seems enough:
diff --git a/spec/handlers/examples/yield_handler_001.rb.txt b/spec/handlers/examples/yield_handler_001.rb.txt
index 668f8183..ecc43276 100644
--- a/spec/handlers/examples/yield_handler_001.rb.txt
+++ b/spec/handlers/examples/yield_handler_001.rb.txt
@@ -1,7 +1,4 @@
class Testing
- # Ignore yields outside methods
- yield x, y, z
-
# Should document this
def mymethod
yield
For now, I am going to create PR (i.e. remove invalid yield usage from spec example). This seems to make spec testsuite pass even on ruby3.3.
Testing yard head ( https://github.com/lsegal/yard/commit/2d197a381c5d4cc5c55b2c60fff992b31c986361 ), with ruby 3.3.0dev spec test fails like below.
So exactly https://github.com/ruby/ruby/commit/b5e23d3e3b5ff2f5328aa43a2392ebe7c951a222 is making yard testsuite fail. I don't know in detail what yard or the above ruby commit does, however it looks like the above ruby commit rejects some of
yield
usage.