Overload disambiguation
For routine calls “overload resolution” is performed. There is a weaker form of overload resolution called overload disambiguation that is performed when an overloaded symbol is used in a context where there is additional type information available. Let p be an overloaded symbol. These contexts are:
- In a function call q(…, p, …) when the corresponding formal parameter of q is a proc type. If q itself is overloaded then the cartesian product of every interpretation of q and p must be considered.
- In an object constructor Obj(…, field: p, …) when field is a proc type. Analogous rules exist for array/set/tuple constructors.
- In a declaration like x: T = p when T is a proc type.
As usual, ambiguous matches produce a compile-time error.
Named argument overloading
Routines with the same type signature can be called individually if a parameter has different names between them.
proc foo(x: int) =
echo "Using x: ", x
proc foo(y: int) =
echo "Using y: ", y
foo(x = 2) # Using x: 2
foo(y = 2) # Using y: 2
Not supplying the parameter name in such cases results in an ambiguity error.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .