lean4-htt/tests/lean/run/5634.lean
Marc Huisinga f180eee7bf
feat: use widget message for "try this" (#9966)
This PR adjusts the "try this" widget to be rendered as a widget message
under 'Messages', not a separate widget under a 'Suggestions' section.
The main benefit of this is that the message of the widget is not
duplicated between 'Messages' and 'Suggestions'.

Since widget message suggestions were already implemented by @jrr6 for
the new hint infrastructure, this PR replaces the old "try this"
implementation with the new hint infrastructure. In doing so, the
`style?` field of suggestions is deprecated, since the hint
infrastructure highlights hints using diff colors, and `style?` also
never saw much use downstream. Additionally, since the message and the
suggestion are now the same component, the `messageData?` field of
suggestions is deprecated as well. Notably, the "Try this:" message
string now also contains a newline and indentation to separate the
suggestion from the rest of the message more clearly and the `postInfo?`
field of the suggestion is now part of the message.

Finally, this PR changes the diff colors used by the hint infrastructure
to be more color-blindness-friendly (insertions are now blue, not green,
and text that remains unchanged is now using the editor foreground color
instead of blue).

### Breaking changes
Tests that use `#guard_msgs` to test the "Try this:" message may need to
be adjusted for the new formatting of the message.
2025-08-26 12:15:32 +00:00

116 lines
2.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-!
# Make sure `simpa` checks for metavariables in `using` clause
https://github.com/leanprover/lean4/issues/5634
-/
set_option linter.unnecessarySimpa true
/-!
This used to have a "don't know how to synthesize placeholder" error on the `have` line too.
This is because `have` is `refine_lift have ...; ?_`, so it indeed had a placeholder.
-/
/--
error: don't know how to synthesize placeholder for argument 'a'
context:
htrue : True
⊢ False
---
error: unsolved goals
htrue : True
h✝ : False
⊢ False
-/
#guard_msgs in
example : False := by
have htrue : True := trivial
simpa using id _
/-!
Simplified version of the test.
-/
/--
error: don't know how to synthesize placeholder for argument 'a'
context:
⊢ False
---
error: unsolved goals
h✝ : False
⊢ False
-/
#guard_msgs in
example : False := by
refine ?_
simpa using id ?_
/-!
Verifying that unassigned metavariables are OK, so long as they come from before elaboring the `using` clause.
-/
example (p : Prop) (h : p) : p := by
have : ?a := ?b
simpa using ?b
exact h
/-!
Occurs check
-/
/--
error: Occurs check failed: Expression
?foo
contains the goal ?foo
-/
#guard_msgs in
example : False := by
refine ?foo
simpa using ?foo
/-!
Regression test: need to synthesize postponed metavariables before metavariable checks.
-/
example (α : Type) (x : α) : Nonempty α := by
simpa using ⟨x⟩
/-!
Regression test: elaborates implicit arguments in the `using` clause
-/
noncomputable example (α : Type) [Nonempty α] : α := by
simpa using fun {β : Type} [inst : Nonempty β] => Classical.choice inst
/-!
Regression test: elaborates using implicit lambda feature
-/
example (p : Prop) (h : p) : ∀ {_ : Nat}, p := by
simpa using h
/-!
Regression test: make sure `simpa?` reports lemmas for both the goal and the `using` clause
-/
/--
info: Try this:
simpa only [id] using h
-/
#guard_msgs in example (p : Prop) (h : p) : id p := by
simpa? only [id] using h
/--
info: Try this:
simpa only [id] using h
-/
#guard_msgs in example (p : Prop) (h : id p) : p := by
simpa? only [id] using h
/-!
Regression test: unnecessary `simpa`
-/
def foo (n : α) := [n]
/--
warning: Try `simp at h` instead of `simpa using h`
Note: This linter can be disabled with `set_option linter.unnecessarySimpa false`
-/
#guard_msgs in
example (h : foo n ≠ [n]) : False := by
simpa [foo] using h