lean4-htt/tests/lean/run/12334.lean
Henrik Böving 8d29c591e6
refactor: behavior of inline annotations in the compiler (#12344)
This PR changes the semantics of `inline` annotations in the compiler.
The behavior of the original `@[inline]` attribute remains the same but
the function `inline` now comes with a restriction that it can only use
declarations that are local to the current module. This comes as a
preparation to pulling the compiler out into a separate process.

Closes: #12334
2026-02-06 10:38:14 +00:00

24 lines
810 B
Text

import Std.Data.HashMap
/-! Test some basic behavior related to `inline` discovered in #12334 -/
#guard_msgs in
def foo {n : Nat} (m : Std.HashMap Nat (Fin n)) : Std.HashMap Nat (Fin (n + 1)) :=
m.map <| inline fun _ ↦ Fin.castSucc
/-- error: `inline` applied to parameters is invalid -/
#guard_msgs in
def params (n : Nat) : Nat := inline n
#guard_msgs in
def inlineLocal {n : Nat} (m : Std.HashMap Nat (Fin n)) : Std.HashMap Nat (Fin (n + 1)) :=
inline <| foo m
/-- error: `inline` applied to constructor 'List.cons' is invalid -/
#guard_msgs in
def inlineCtor (x : Nat) (xs : List Nat) := inline <| List.cons x xs
/-- error: `inline` applied to non-local declaration 'Lean.Name.mkStr3' is invalid -/
#guard_msgs in
def inlineNonLocal (s1 s2 s3 : String) :=
inline <| Lean.Name.mkStr3 s1 s2 s3