Skip to content

CodeQL Ruby parser fails on bare & block forwarding in multi-line method calls #20257

@landongrindheim

Description

@landongrindheim

🖼️ Context

CodeQL's Ruby parser encounters parse errors when using Ruby 3.1+'s anonymous block forwarding syntax (&) in specific contexts, despite this being valid Ruby syntax.

Reproduction Case

  module TestCase
    def method_with_bare_ampersand(&)
      some_method_call(
        keyword_arg1: "value1",
        keyword_arg2: "value2",
        keyword_arg3: "value3",
        &  # <-- CodeQL parse error occurs here
      )
    end

    # This works fine - single line call
    def working_method(&)
      simple_call(&)
    end

    private

    def some_method_call(keyword_arg1:, keyword_arg2:, keyword_arg3:, &block)
      yield if block_given?
    end

    def simple_call(&block)
      yield if block_given?
    end
  end

Environment

📝 Notes

  • The issue only occurs with multi-line method calls where & appears on its own line
  • Single-line calls with & work correctly
  • Named block parameters (e.g., &block) work in all contexts
  • This is valid Ruby 3.1+ anonymous block forwarding syntax

Impact

This prevents CodeQL security analysis on codebases using modern Ruby block forwarding patterns, forcing developers to use less idiomatic code or exclude files from analysis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions