Auto type
The auto type can only be used for return types and parameters. For return types it causes the compiler to infer the type from the routine body:
proc returnsInt(): auto = 1984
For parameters it currently creates implicitly generic routines:
proc foo(a, b: auto) = discard
Is the same as:
proc foo[T1, T2](a: T1, b: T2) = discard
However later versions of the language might change this to mean “infer the parameters’ types from the body”. Then the above foo would be rejected as the parameters’ types can not be inferred from an empty discard statement.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .