diff --git a/src/frontends/lean/scanner.cpp b/src/frontends/lean/scanner.cpp index 41b1184f9..ce7c2496a 100644 --- a/src/frontends/lean/scanner.cpp +++ b/src/frontends/lean/scanner.cpp @@ -348,40 +348,39 @@ auto scanner::read_key_cmd_id() -> token_kind { } } } - unsigned i = 0; - token_table const * it = find(*m_tokens, cs[i]); + token_table const * it = m_tokens; token_info const * info = nullptr; unsigned key_sz = 0; unsigned key_utf_sz = 0; - unsigned aux_num_utfs = id_utf_sz; - if (it) { - if (aux_num_utfs == 0) - aux_num_utfs = 1; - info = value_of(*it); - if (info) { + while (i < id_sz) { + it = find(*it, cs[i]); + i++; + if (!it) + break; + if (auto new_info = value_of(*it)) { lean_assert(m_uskip == 0); - key_sz = 1; - key_utf_sz = aux_num_utfs; + info = new_info; + key_sz = i; + key_utf_sz = id_utf_sz; // this is imprecise if key_sz < id_sz, but this case is irrelevant } - while (it) { - i++; - if (i == cs.size()) { - next_utf(cs); - num_utfs++; - aux_num_utfs = num_utfs; - } - it = find(*it, cs[i]); - if (it) { - if (auto new_info = value_of(*it)) { - lean_assert(m_uskip == 0); - info = new_info; - key_sz = i+1; - key_utf_sz = aux_num_utfs; - } - } else { - break; - } + } + + while (it) { + if (i == cs.size()) { + next_utf(cs); + num_utfs++; + } + it = find(*it, cs[i]); + i++; + if (!it) + break; + if (auto new_info = value_of(*it)) { + lean_assert(m_uskip == 0); + info = new_info; + key_sz = i; + key_utf_sz = num_utfs; + lean_assert(key_sz > id_sz); } } diff --git a/tests/lean/626c.lean b/tests/lean/626c.lean new file mode 100644 index 000000000..27375a477 --- /dev/null +++ b/tests/lean/626c.lean @@ -0,0 +1,14 @@ +notation `C⁽` := nat +definition foo (c : C⁽) := nat.rec_on c _ _ + +notation `α⁽` := nat +definition foo (c : α⁽) := nat.rec_on c _ _ + +notation `_⁽` := nat +definition foo (c : _⁽) := nat.rec_on c _ _ + +notation `C.⁽` := nat +definition foo (c : C.⁽) := nat.rec_on c _ _ + +notation `C⁽C⁽` := nat +definition foo (c : C⁽C⁽) := nat.rec_on c _ _ diff --git a/tests/lean/626c.lean.expected.out b/tests/lean/626c.lean.expected.out new file mode 100644 index 000000000..e1c87b6ac --- /dev/null +++ b/tests/lean/626c.lean.expected.out @@ -0,0 +1,70 @@ +626c.lean:2:27: error: don't know how to synthesize placeholder +c : C⁽ +⊢ C⁽ → Type +626c.lean:2:40: error: don't know how to synthesize placeholder +c : C⁽ +⊢ ?M_1 +626c.lean:2:42: error: don't know how to synthesize placeholder +c : C⁽ +⊢ Π (a : C⁽), + ?M_1 → ?M_1 +626c.lean:2:27: error: failed to add declaration 'foo' to environment, value has metavariables +remark: set 'formatter.hide_full_terms' to false to see the complete term + λ (c : C⁽), + nat.rec_on c ?M_2 ?M_3 +626c.lean:5:27: error: don't know how to synthesize placeholder +c : α⁽ +⊢ α⁽ → Type +626c.lean:5:40: error: don't know how to synthesize placeholder +c : α⁽ +⊢ ?M_1 +626c.lean:5:42: error: don't know how to synthesize placeholder +c : α⁽ +⊢ Π (a : α⁽), + ?M_1 → ?M_1 +626c.lean:5:27: error: failed to add declaration 'foo' to environment, value has metavariables +remark: set 'formatter.hide_full_terms' to false to see the complete term + λ (c : α⁽), + nat.rec_on c ?M_2 ?M_3 +626c.lean:8:27: error: don't know how to synthesize placeholder +c : _⁽ +⊢ _⁽ → Type +626c.lean:8:40: error: don't know how to synthesize placeholder +c : _⁽ +⊢ ?M_1 +626c.lean:8:42: error: don't know how to synthesize placeholder +c : _⁽ +⊢ Π (a : _⁽), + ?M_1 → ?M_1 +626c.lean:8:27: error: failed to add declaration 'foo' to environment, value has metavariables +remark: set 'formatter.hide_full_terms' to false to see the complete term + λ (c : _⁽), + nat.rec_on c ?M_2 ?M_3 +626c.lean:11:28: error: don't know how to synthesize placeholder +c : C.⁽ +⊢ C.⁽ → Type +626c.lean:11:41: error: don't know how to synthesize placeholder +c : C.⁽ +⊢ ?M_1 +626c.lean:11:43: error: don't know how to synthesize placeholder +c : C.⁽ +⊢ Π (a : C.⁽), + ?M_1 → ?M_1 +626c.lean:11:28: error: failed to add declaration 'foo' to environment, value has metavariables +remark: set 'formatter.hide_full_terms' to false to see the complete term + λ (c : C.⁽), + nat.rec_on c ?M_2 ?M_3 +626c.lean:14:29: error: don't know how to synthesize placeholder +c : C⁽C⁽ +⊢ C⁽C⁽ → Type +626c.lean:14:42: error: don't know how to synthesize placeholder +c : C⁽C⁽ +⊢ ?M_1 +626c.lean:14:44: error: don't know how to synthesize placeholder +c : C⁽C⁽ +⊢ Π (a : C⁽C⁽), + ?M_1 → ?M_1 +626c.lean:14:29: error: failed to add declaration 'foo' to environment, value has metavariables +remark: set 'formatter.hide_full_terms' to false to see the complete term + λ (c : C⁽C⁽), + nat.rec_on c ?M_2 ?M_3