Skip to content

Ruby >= 4.1.0 allows trailing comma in method signature#1178

Merged
tompng merged 1 commit intoruby:masterfrom
eikes:remove-color-test-for-trailing-comma-in-method-definition
Feb 25, 2026
Merged

Ruby >= 4.1.0 allows trailing comma in method signature#1178
tompng merged 1 commit intoruby:masterfrom
eikes:remove-color-test-for-trailing-comma-in-method-definition

Conversation

@eikes
Copy link
Contributor

@eikes eikes commented Feb 25, 2026

See "Allow trailing comma in method signature":

https://bugs.ruby-lang.org/issues/19107
ruby/prism#3920

So this is now valid ruby:

def f(a,)

The colorize special code test is no longer passing because of this change in latest Prism: https://github.com/ruby/irb/actions/runs/22390686601/job/64811636988

This PR fixes the failing test with latest Prism here by removing this special case from the color test.

I noticed this failure in the following PR, which will pass after merging this PR: #1177

See "Allow trailing comma in method signature": ruby/prism#3920

This test is no longer passing because of the change in Prism.
@eikes
Copy link
Contributor Author

eikes commented Feb 25, 2026

Alternatively the Prism version could be inspected and the test adapted:

    def test_colorize_trailing_comma_in_method_definition_complete_false
      prism_1_9_1_or_later = ENV['PRISM_VERSION'] == 'latest' || Gem::Version.new(Prism::VERSION) >= Gem::Version.new('1.9.1')
      
      code = "def f(a,)" 

      result = if prism_1_9_1_or_later 
        "#{GREEN}def#{CLEAR} #{BLUE}#{BOLD}f#{CLEAR}(a,)" 
      else
        "#{GREEN}def#{CLEAR} #{BLUE}#{BOLD}f#{CLEAR}(a#{RED}#{REVERSE},#{CLEAR})"
      end

      assert_equal_with_term(result, code, complete: false)

      assert_equal_with_term(code, code, complete: false, tty: false)

      assert_equal_with_term(code, code, complete: false, colorable: false)

      assert_equal_with_term(result, code, complete: false, tty: false, colorable: true)
    end

@eikes eikes changed the title Ruby / Prism >= 4.1.0 allows trailing comma in method definition Ruby >= 4.1.0 allows trailing comma in method definition Feb 25, 2026
@eikes eikes changed the title Ruby >= 4.1.0 allows trailing comma in method definition Ruby >= 4.1.0 allows trailing comma in method signature Feb 25, 2026
@tompng tompng merged commit 9d9f0a8 into ruby:master Feb 25, 2026
40 checks passed
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.

2 participants