From 9560e49e8fa412839743aa86400bd73e2c57ab3d Mon Sep 17 00:00:00 2001 From: IDF Date: Tue, 6 Oct 2020 17:49:30 +0300 Subject: New hint for unused exceptions in .raises (#15492) * New hint for unused exceptions in .raises * Fix effects test * Further adapt teffects1.nim --- compiler/lineinfos.nim | 4 +++- compiler/sempass2.nim | 8 +++++--- tests/effects/teffects1.nim | 7 ++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim index c9821ac9f..db0569fda 100644 --- a/compiler/lineinfos.nim +++ b/compiler/lineinfos.nim @@ -58,6 +58,7 @@ type warnUser, hintSuccess, hintSuccessX, hintCC, hintLineTooLong, hintXDeclaredButNotUsed, + hintXCannotRaiseY, hintConvToBaseNotNeeded, hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled, hintProcessing, hintCodeBegin, hintCodeEnd, hintConf, hintPath, @@ -131,6 +132,7 @@ const hintCC: "CC: $1", hintLineTooLong: "line too long", hintXDeclaredButNotUsed: "'$1' is declared but not used", + hintXCannotRaiseY: "$1", hintConvToBaseNotNeeded: "conversion to base object is not needed", hintConvFromXtoItselfNotNeeded: "conversion from $1 to itself is pointless", hintExprAlwaysX: "expression evaluates always to '$1'", @@ -179,7 +181,7 @@ const HintsToStr* = [ "Success", "SuccessX", "CC", "LineTooLong", - "XDeclaredButNotUsed", + "XDeclaredButNotUsed", "XCannotRaiseY", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded", "ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf", "Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency", diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 19223b88f..4eac6ef13 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -1140,7 +1140,8 @@ proc subtypeRelation(g: ModuleGraph; spec, real: PNode): bool = return safeInheritanceDiff(g.excType(real), spec.typ) <= 0 proc checkRaisesSpec(g: ModuleGraph; spec, real: PNode, msg: string, hints: bool; - effectPredicate: proc (g: ModuleGraph; a, b: PNode): bool {.nimcall.}) = + effectPredicate: proc (g: ModuleGraph; a, b: PNode): bool {.nimcall.}; + hintsArg: PNode = nil) = # check that any real exception is listed in 'spec'; mark those as used; # report any unused exception var used = initIntSet() @@ -1158,7 +1159,8 @@ proc checkRaisesSpec(g: ModuleGraph; spec, real: PNode, msg: string, hints: bool if hints: for s in 0.. but expected 'MyProcType = proc (x: int): string{.closure.}' +.raise effects differ''' """ type @@ -12,7 +17,7 @@ type proc forw: int {. .} proc lier(): int {.raises: [IO2Error].} = - #[tt.Hint ^ 'IO2Error' is declared but not used [XDeclaredButNotUsed] ]# + #[tt.Hint ^ 'lier' cannot raise 'IO2Error' [XCannotRaiseY] ]# writeLine stdout, "arg" #[tt.Error ^ can raise an unlisted exception: ref IOError ]# -- cgit 1.4.1-2-gfad0