Skip to content

Commit

Permalink
Convert kwarg_problems_for to focus on one parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
apiology committed Oct 14, 2024
1 parent 60a16f8 commit f7b5d24
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions lib/solargraph/type_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,30 +327,29 @@ def argument_problems_for chain, api_map, block_pin, locals, location
result
end

def kwarg_problems_for argchain, api_map, block_pin, locals, location, pin, params, first
def kwarg_problems_for argchain, api_map, block_pin, locals, location, pin, params, idx
result = []
kwargs = convert_hash(argchain.node)
pin.signatures.first.parameters[first..-1].each_with_index do |par, cur|
idx = first + cur
argchain = kwargs[par.name.to_sym]
if par.decl == :kwrestarg || (par.decl == :optarg && idx == pin.parameters.length - 1 && par.asgn_code == '{}')
result.concat kwrestarg_problems_for(api_map, block_pin, locals, location, pin, params, kwargs)
else
if argchain
data = params[par.name]
if data.nil?
# @todo Some level (strong, I guess) should require the param here
else
ptype = data[:qualified]
next if ptype.undefined?
par = pin.signatures.first.parameters[idx]
argchain = kwargs[par.name.to_sym]
if par.decl == :kwrestarg || (par.decl == :optarg && idx == pin.parameters.length - 1 && par.asgn_code == '{}')
result.concat kwrestarg_problems_for(api_map, block_pin, locals, location, pin, params, kwargs)
else
if argchain
data = params[par.name]
if data.nil?
# @todo Some level (strong, I guess) should require the param here
else
ptype = data[:qualified]
unless ptype.undefined?
argtype = argchain.infer(api_map, block_pin, locals)
if argtype.defined? && ptype && !any_types_match?(api_map, ptype, argtype)
result.push Problem.new(location, "Wrong argument type for #{pin.path}: #{par.name} expected #{ptype}, received #{argtype}")
end
end
elsif par.decl == :kwarg
result.push Problem.new(location, "Call to #{pin.path} is missing keyword argument #{par.name}")
end
elsif par.decl == :kwarg
result.push Problem.new(location, "Call to #{pin.path} is missing keyword argument #{par.name}")
end
end
result
Expand Down

0 comments on commit f7b5d24

Please sign in to comment.