From d9abcff39a907c10569a75e2df1bba843db202ba Mon Sep 17 00:00:00 2001 From: thorimur <68410468+thorimur@users.noreply.github.com> Date: Wed, 20 Sep 2023 14:17:39 -0400 Subject: [PATCH] feat: fail if `suggestions` is empty --- Std/Tactic/TryThis.lean | 1 + test/tryThis.lean | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Std/Tactic/TryThis.lean b/Std/Tactic/TryThis.lean index 33fafbe4ec..eb2cf0f911 100644 --- a/Std/Tactic/TryThis.lean +++ b/Std/Tactic/TryThis.lean @@ -428,6 +428,7 @@ The parameters are: def addSuggestions (ref : Syntax) (suggestions : Array Suggestion) (origSpan? : Option Syntax := none) (header : String := "Try these:") : MetaM Unit := do + if suggestions.isEmpty then throwErrorAt ref "no suggestions available" let msgs := suggestions.map toMessageData let msgs := msgs.foldl (init := MessageData.nil) (fun msg m => msg ++ m!"\n• " ++ m) logInfoAt ref m!"{header}{msgs}" diff --git a/test/tryThis.lean b/test/tryThis.lean index 32d45c02c9..e012ec8242 100644 --- a/test/tryThis.lean +++ b/test/tryThis.lean @@ -186,3 +186,7 @@ info: Grab bag: postInfo? := " at 0.166667.", style? := some (.value (1/6))} ] with_header "Grab bag:" + +/-- error: no suggestions available -/ +#guard_msgs in +#demo #[]