How do TupleExprs get their arguments mapped?

Here's what I wanted to understand:

Suppose we have a simple function that is declared and then called:

func f(a: Int, b: Int) { }
f(a: 1, b: 2)

It's easy to know here that a has a value of 1 and b has a value of 2. However, this can get more complicated when we consider there can be default values, variadics, arguments with no names, etc:

func g(_ a: Int, _ b: Int = 0, _ c: Int, _ d: Int...) { }
g(1, 2, 3, 4, 5)

Now, I assume there's a strict set of rules that determine which values go to which arguments. Are they documented somewhere? Is there an algorithm somewhere in the compiler that explains this process?

Check out matchCallArgumentsImpl in CSSimplify.

Thanks! But wow, that's a lot more complicated than I hoped it'd be. Do you know if there's any way to obtain this information using something like SwiftSyntax or SourceKit?

Terms of Service

Privacy Policy

Cookie Policy