diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim index 3fa6cce69f..c564a52b61 100644 --- a/compiler/lineinfos.nim +++ b/compiler/lineinfos.nim @@ -44,6 +44,7 @@ type warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed, warnInconsistentSpacing, warnCaseTransition, warnCycleCreated, warnObservableStores, + warnResultUsed, warnUser, hintSuccess, hintSuccessX, hintCC, hintLineTooLong, hintXDeclaredButNotUsed, @@ -110,6 +111,7 @@ const warnCaseTransition: "Potential object case transition, instantiate new object instead", warnCycleCreated: "$1", warnObservableStores: "observable stores to '$1'", + warnResultUsed: "used 'result' variable", warnUser: "$1", hintSuccess: "operation successful: $#", # keep in sync with `testament.isSuccess` @@ -160,7 +162,7 @@ const "IndexCheck", "GcUnsafe", "GcUnsafe2", "Uninit", "GcMem", "Destructor", "LockLevel", "ResultShadowed", "Spacing", "CaseTransition", "CycleCreated", - "ObservableStores", "User"] + "ObservableStores", "ResultUsed", "User"] HintsToStr* = [ "Success", "SuccessX", "CC", "LineTooLong", @@ -191,7 +193,7 @@ type TNoteKinds* = set[TNoteKind] proc computeNotesVerbosity(): array[0..3, TNoteKinds] = - result[3] = {low(TNoteKind)..high(TNoteKind)} - {} + result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnResultUsed} result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext} result[1] = result[2] - {warnProveField, warnProveIndex, warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd, diff --git a/compiler/options.nim b/compiler/options.nim index c2098a324b..975c767e6f 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -310,7 +310,7 @@ proc setNote*(conf: ConfigRef, note: TNoteKind, enabled = true) = proc hasHint*(conf: ConfigRef, note: TNoteKind): bool = optHints in conf.options and note in conf.notes -proc hasWarn*(conf: ConfigRef, note: TNoteKind): bool = +proc hasWarn*(conf: ConfigRef, note: TNoteKind): bool {.inline.} = optWarns in conf.options and note in conf.notes proc hcrOn*(conf: ConfigRef): bool = return optHotCodeReloading in conf.globalOptions diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 07a8f69523..080ee9b6d1 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1207,6 +1207,9 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode = # not sure the symbol really ends up being used: # var len = 0 # but won't be called # genericThatUsesLen(x) # marked as taking a closure? + if hasWarn(c.config, warnResultUsed): + message(c.config, n.info, warnResultUsed) + of skGenericParam: onUse(n.info, s) if s.typ.kind == tyStatic: