`NameTrie.findLongestPrefix?` returns `none` when the lookup passes through a key-less node before leaving the trie
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend
Research direction
Start with PrefixTreeNode.findLongestPrefix? and its loop in src/Lean/Data/PrefixTree.lean; the issue identifies the missing fallback when a lookup leaves the trie. Check the caller AsyncConsts.findPrefix? in src/Lean/Environment.lean for context. Done means both lookups in the reproducer return some 1.
Written by the indexing model from the issue text.
Description
Prerequisites
- Check that your issue is not already filed: searched for
findLongestPrefix,PrefixTree,NameTrieandAsyncConsts. - Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to Mathlib or Batteries.
- Test your test case against the latest nightly release.
Description
With keys a and a.b.c, findLongestPrefix? a.b.d returns none, although a is a key and a prefix of a.b.d:
import Lean.Data.NameTrie
open Lean
-- Keys: `a` ↦ 1 and `a.b.c` ↦ 2. The node for `a.b` exists but holds no value.
def t : NameTrie Nat := ((∅ : NameTrie Nat).insert `a 1).insert `a.b.c 2
#eval t.findLongestPrefix? `a.x -- some 1
#eval t.findLongestPrefix? `a.b.d -- none, expected some 1
The docstring of PrefixTreeNode.findLongestPrefix? (src/Lean/Data/PrefixTree.lean) says: "Returns the value of the longest key in t that is a prefix of k, if any."
The first lookup leaves the trie at the node for a, which has a value. The second goes through the node for a.b, which has none, and then leaves the trie. In findLongestPrefix?.loop, the [] case returns val <|> acc?, but the m.get? k = none case returns only val and drops acc?, the best match found higher up.
Expected behavior: some 1 for both lookups.
Actual behavior: some 1, then none.
Versions
4.37.0-nightly-2026-11-05 some 1 / none
4.36.0-rc2 some 1 / none
4.35.0 some 1 / none
These are on macOS arm64 (official toolchains via elan), and Linux x86_64 gives the same results. PrefixTree.lean and NameTrie.lean have not changed on master since the nightly. The function was added in #6691 (v4.17.0).
Additional Information
The in-tree caller is AsyncConsts.findPrefix? in src/Lean/Environment.lean.
A fix is available (one line: | none => val <|> acc?).
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask
them to add 👍 to it.
Found by an automated differential tester (ephyra); this report was drafted with AI assistance.
- Dominant language
- Lean
- Stars
- 10.3k
- Forks
- 1.1k
- Avg merge
- 19h 8m
- Merged PRs (30d)
- 421
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from leanprover/lean4
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
leanprover/lean4#16305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16257 ·
Maintainers usually reply within 1 day
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
leanprover/lean4#15683 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
leanprover/lean4#15626 ·
Maintainers usually reply within 1 day
All issues in leanprover/lean4
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vllm-project/vllm-sail#398 ·
Maintainers usually reply within 1 day
-
kubernetes-ingestor: fetchCRDMapping() runs even when crossplane.enabled is false, logging a 403 ERROR every runPossibly taken @kc9ddi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TeraSky-OSS/backstage-plugins#228 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
nightscout/nocturne#4057 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
opendatalab/MinerU#5800 · 2 comments ·
Maintainers usually reply within 1 day