Files
Nim/tests/msgs/tresultused.nim
ringabout 0ec8682abe fixes #26062; ResultUsed warning behaves inconsistently with manual c… (#26087)
…haracterization with--warning:ResultUsed:on


fixes #26062


> A return statement with no expression is shorthand for return result.

> ResultUsed: Warn about the usage of the built-in result variable.

> A procedure that does not have any return statement and does not use
the special result variable returns the value of its last expression.
2026-08-10 07:38:49 +02:00

43 lines
712 B
Nim

discard """
action: compile
cmd: "nim check --hints:off --warning:ResultUsed:on $file"
nimout: '''
tresultused.nim(34, 3) Warning: used 'result' variable [ResultUsed]
tresultused.nim(37, 3) Warning: used 'result' variable [ResultUsed]
'''
"""
let value = 0
discard value
for item in 0 .. 0:
discard item
proc usesLocal() =
var local = 0
discard local
block:
let result = 0
discard result
proc voidReturn() =
return
proc implicitReturn(): int =
0
proc explicitReturn(): int =
return 0
proc usesResult(): int =
result = 0
proc usesBareReturn(): int =
return
doAssert implicitReturn() == 0
doAssert explicitReturn() == 0
doAssert usesResult() == 0
doAssert usesBareReturn() == 0