Skip to content

Commit 9445d1f

Browse files
apiologyclaude
andcommitted
Fix chain.rb nil-safety instead of suppressing the typecheck warning
apiology asked, on the receiver_path plumbing added for castwide#1249, whether the @sg-ignore on links.last.resolve was hiding a real bug rather than a false positive. It wasn't reachable (Chain's constructor pads an empty links array with UNDEFINED_CALL, so links is never empty, but suppressing it instead of expressing that invariant in the code was the wrong call. Extract links.last once and guard it for real. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KGu6zb5faStTC754PxMUSA EOF )
1 parent c2a16e5 commit 9445d1f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/solargraph/source/chain.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ def define api_map, name_pin, locals
137137
"Chain#define(links=#{links.map(&:desc)}, name_pin=#{name_pin.inspect}, locals=#{locals}) - after processing #{link.desc}, new working_pin=#{working_pin} with binder #{working_pin.binder}"
138138
end
139139
end
140-
links.last.last_context = working_pin
141-
# @sg-ignore Need to add nil check here
142-
links.last.resolve(api_map, working_pin, locals, receiver_path)
140+
# links is never empty -- the constructor pads an empty links
141+
# array with UNDEFINED_CALL -- but Array#last is typed nilable.
142+
last_link = links.last
143+
return [] if last_link.nil?
144+
145+
last_link.last_context = working_pin
146+
last_link.resolve(api_map, working_pin, locals, receiver_path)
143147
end
144148

145149
# @param api_map [ApiMap]

0 commit comments

Comments
 (0)