leanprover / leanprover/lean4

Failed to find LCNF signature for constructor parameter using `match`

Open
#14,378 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

When a constructor parameter depends on a noncomputable expression and includes a matcher (or more precisely a casesOn-like), the compiler errors with "Failed to find LCNF signature". This is a special case of a more general problem where matchers in constructor parameters cause code duplication and redundant matches.

Context

Discussion with @hargoniX about the underlying issue regarding constructor parameters.

Steps to Reproduce
inductive ManyCases where
  | a
  | b
  | c
  | d
deriving Nonempty

inductive Thing (x : Nat) where
  | myCtor1 (a : Nat)
  | myCtor2 (b : Nat)

@[inline]
def ManyCases.toNat : ManyCases → Nat
  | .a => 3
  | _ => 7

/-- error: Failed to find LCNF signature for Classical.ofNonempty -/
#guard_msgs in
def test : Thing (ManyCases.toNat Classical.ofNonempty) :=
  .myCtor1 1

Expected behavior:
Constructor parameters are irrelevant -- the example should compile without errors.

Actual behavior:
The compiler produces an unhelpful error message "Failed to find LCNF signature".

Versions

Lean 4.33.0, commit 12c859a4d735fbcdb3ebbddb42dcc8619bcc7a7d

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Lean reproducer in the issue and inspect the compiler path that handles constructor parameters containing matchers or casesOn-like expressions. Trace the reported “Failed to find LCNF signature” for Classical.ofNonempty. Done means the reproducer compiles without the error while preserving the expected constructor behavior.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.