Strip nil from or-expression fallbacks in conditional branch values - #1309
Draft
apiology wants to merge 1 commit into
Draft
Strip nil from or-expression fallbacks in conditional branch values#1309apiology wants to merge 1 commit into
apiology wants to merge 1 commit into
Conversation
reduce_to_value_nodes flattened an :or node into both operand nodes, so each was typed independently and unioned -- bypassing Chain::Or, which already strips nil from the union when the right operand is not nullable. A bare 'x || fallback' method tail inferred correctly, but the same expression as an if/else branch value leaked the left operand's nil into the method's inferred return type. Keep the :or node whole so it routes through Chain::Or like any other or-expression.
apiology
added a commit
to apiology/solargraph
that referenced
this pull request
Aug 16, 2026
…ional branch values # Conflicts: # lib/solargraph/parser/parser_gem/node_methods.rb
apiology
added a commit
to apiology/solargraph
that referenced
this pull request
Aug 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At strong level, a method whose declared
@returnis::Booleanis flaggedDeclared return type ::Boolean does not match inferred type ::Boolean, nilwhen an or-expression with a nullable left operand is the value of a conditional branch ��� even though nil can't escape the||:m <= expected || fallbackas method tail::Boolean���return fallback if m.nil?guard::Boolean���::Boolean, nil���Root cause:
DeepInference.reduce_to_value_nodesflattens an:ornode into both operand nodes, typing each independently and unioning ��� bypassingChain::Or#resolve, which strips nil from the union unless every operand is nullable. Method-tail or-expressions go through NodeChainer ���Chain::Orand get that treatment; conditional branch values go throughreduce_to_value_nodesand don't.The fix drops the
:orspecial case so the node stays whole and routes throughChain::Orlike any other or-expression. Two existing node-level specs pinned the flattening as a contract (return 1 || "2"��� two literal nodes); updated to expect the intact:ornode ��� the operand union is preserved byChain::Or.Test plan:
���� This PR was written by Claude (Anthropic's AI assistant) on behalf of @apiology.
���� Generated with Claude Code
https://claude.ai/code/session_01H1FEjW6nMpZrWPmeWX9miT