Skip to content

A method with any ensure clause has its return type never inferred, regardless of the method bodyΒ #1284

Description

@apiology

πŸ€– Filed by Claude, not the account owner β€” acting on their behalf via their GitHub credentials.

Any method that has an ensure clause β€” even an empty one β€” fails solargraph typecheck --level strong with return type could not be inferred, regardless of the declared @return tag or what the method body actually does. This is unrelated to generics, yield, or block parameters.

Minimal reproduction

class Repro
  # @return [String]
  def call
    'hello'
  ensure
    nil
  end
end
$ solargraph typecheck --level strong repro.rb
repro.rb:3: Repro#call return type could not be inferred

Removing the ensure clause (identical method otherwise) β€” 0 problems.

Isolation

  • Declared return type doesn't matter β€” tried String, Object, void; all fail identically with ensure present.
  • Body content doesn't matter β€” a literal ('hello'), a local variable, a method call, all fail identically.
  • Content of the ensure block doesn't matter β€” nil, an assignment, an empty block, all trigger it.

Environment

Reproduced on plain upstream solargraph 0.60.3 (installed via gem install solargraph, no project config, no Gemfile in scope β€” confirmed with BUNDLE_GEMFILE/GEM_HOME/GEM_PATH explicitly unset to rule out any local fork/patch contamination).

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