Fixed bug in argument/parameter matching when an unpack operator is used in the argument and the parameter is a *varg type.

This commit is contained in:
Eric Traut 2020-07-16 15:44:10 -07:00
parent 579fb7be69
commit 087de50ae6
2 changed files with 25 additions and 11 deletions

View File

@ -5056,7 +5056,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, printTypeFlags:
paramMap.get(paramName)!.argsReceived++;
}
if (advanceToNextArg) {
if (advanceToNextArg || typeParams[paramIndex].category === ParameterCategory.VarArgList) {
argIndex++;
}
paramIndex++;

View File

@ -1,23 +1,25 @@
# This sample tests function parameter matching logic.
def func1(a: int, *b: int):
pass
func1(3)
func1(3, 4)
func1(3, *[1, 2, 3])
# This should generate an error
func1(3, 'hello')
func1(3, "hello")
# This should generate an error
func1(3, 5, 2, 'str')
func1(3, 5, 2, "str")
# This should generate an error
func1('hello', 3)
func1("hello", 3)
# This should generate an error
str_list = ['he', '2', '3']
str_list = ["he", "2", "3"]
func1(3, *str_list)
@ -25,17 +27,29 @@ def func2(a: str, **b: int):
pass
func2('hi')
func2('hi', b=3, c=4, d=5)
func2("hi")
func2("hi", b=3, c=4, d=5)
str_dict = {'a': '3', 'b': '2'}
func2('hi', **str_dict)
str_dict = {"a": "3", "b": "2"}
func2("hi", **str_dict)
# This should generate a type error
func2('hi', 3)
func2("hi", 3)
# This should generate a type error
func2('hi', b='hi')
func2("hi", b="hi")
def func4(*args: int):
pass
def func5(a: int, *args):
pass
tuple1 = (2, 3)
func4(*tuple1)
func5(*tuple1)