Void context
In a list of statements, every expression except the last one needs to have the type void. In addition to this rule an assignment to the builtin result symbol also triggers a mandatory void context for the subsequent expressions:
proc invalid*(): string =
result = "foo"
"invalid" # Error: value of type 'string' has to be discarded
proc valid*(): string =
let x = 317
"valid"
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .