Repository navigation
Commit c13f01e
committed
scopes: a namespace body is not a function body — the parameters of a
Two reports from a reader, both in a body written inside a namespace:
```text
archive.cpp void Archive::put(const Entry& entry) { _counts[entry.key] += entry.count; }
`entry` is not declared: nothing this file can see names it
report.cpp void Report::add(std::string line) { lines.push_back(std::move(line)); }
hovering `line` answered std::source_location::line
```
# One rule, one line of the grammar
`ScopeWalker::declaration` skips a `::`-qualified declaration nested in a `CompoundStat`, because the most-vexing-parse
reading of a *call statement* is exactly that shape (`std::iter_swap(__result, __b);` bound a phantom function in `std`).
The test was `ancestors().any(CppCompoundStat)` — and **a namespace's body is a `CompoundStat` too**, so every
out-of-class member definition written inside `namespace archive { … }`, the layout of every `.cpp` there is, was
dropped whole: no function scope, no parameter bindings, and every name in the body looked up as if it had been written
at namespace scope. `line` then found `std::source_location::line`, which is exactly the hover that was reported.
The rule is about the *parent* of the compound: a function's body hangs off the declaration, a branch's off the `if`,
and a namespace's off the `NamespaceDecl` — a scope, not a body.
# The second rule the report exposed
With the declaration read again, the qualifier had to be found. `scope_of_a_qualifier` matches the name **as written**
against the table's absolute qualified names, so `Archive` inside `namespace report` matched nothing (the class is
`report::Archive`) and the definition took the "the class is in a header" path anyway. The lookup now tries the enclosing
scopes first and the absolute name second, which is the order the language uses.
# Verified on the reported project
`tests/reported_parameters.rs` (ignored; skips without the fixture) opens both files and asks the reader's questions:
```text
before archive.cpp: "_counts[entry.key]" → Unknown(NotDeclaredHere("entry"))
archive.cpp: 7 check(s) UndefinedName: `entry` is not declared: nothing this file can see names it
report.cpp: "std::move(line)" → Unknown(NotDeclaredHere("line"))
after archive.cpp: "_counts[entry.key]" → entry in archive.cpp
report.cpp: "std::move(line)" → line in report.cpp
archive.cpp: 0 error(s), 0 check(s)
report.cpp: 0 error(s), 0 check(s)
```
`tests/session/tests.rs::a_parameter_of_an_out_of_class_definition_is_declared` is the same shape in memory, so the
regression runs without the fixture.
# What did *not* reproduce
The second image's `param-type-check` — *"this passes `std::move(line)` where `const _Ty&` is declared for `push_back`"* —
did not appear in this reading, before the fix or after it (`report.cpp: 0 check(s)` in both). A rule was tried for it
(a template parameter is `Unknown` before the relation is asked) and **reverted**, because no test could make it differ
from the existing behaviour: the class-case guard already answers `Unknown` for `_Ty`, `T`, `_Tp` and their reference
spellings. The hover and the "not declared" errors were the same unresolved-parameter defect and are fixed; if the type
check comes back it is a separate report with its own reproduction.
`cargo test --workspace`: 146 suites, 0 failures..cpp's definitions are declared again1 parent fc169a6 commit c13f01e
3 files changed
Lines changed: 285 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1329 | 1329 | | |
1330 | 1330 | | |
1331 | 1331 | | |
1332 | | - | |
1333 | | - | |
| 1332 | + | |
| 1333 | + | |
1334 | 1334 | | |
1335 | 1335 | | |
1336 | 1336 | | |
1337 | 1337 | | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
1338 | 1352 | | |
1339 | | - | |
1340 | | - | |
1341 | | - | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
1342 | 1359 | | |
1343 | 1360 | | |
1344 | 1361 | | |
| |||
1364 | 1381 | | |
1365 | 1382 | | |
1366 | 1383 | | |
1367 | | - | |
| 1384 | + | |
1368 | 1385 | | |
1369 | 1386 | | |
1370 | 1387 | | |
| |||
1715 | 1732 | | |
1716 | 1733 | | |
1717 | 1734 | | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
1718 | 1819 | | |
1719 | 1820 | | |
1720 | 1821 | | |
| |||
1767 | 1868 | | |
1768 | 1869 | | |
1769 | 1870 | | |
1770 | | - | |
| 1871 | + | |
1771 | 1872 | | |
1772 | 1873 | | |
1773 | 1874 | | |
| |||
1866 | 1967 | | |
1867 | 1968 | | |
1868 | 1969 | | |
1869 | | - | |
| 1970 | + | |
| 1971 | + | |
1870 | 1972 | | |
1871 | 1973 | | |
1872 | 1974 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4949 | 4949 | | |
4950 | 4950 | | |
4951 | 4951 | | |
| 4952 | + | |
| 4953 | + | |
| 4954 | + | |
| 4955 | + | |
| 4956 | + | |
| 4957 | + | |
| 4958 | + | |
| 4959 | + | |
| 4960 | + | |
| 4961 | + | |
| 4962 | + | |
| 4963 | + | |
| 4964 | + | |
| 4965 | + | |
| 4966 | + | |
| 4967 | + | |
| 4968 | + | |
| 4969 | + | |
| 4970 | + | |
| 4971 | + | |
| 4972 | + | |
| 4973 | + | |
| 4974 | + | |
| 4975 | + | |
| 4976 | + | |
| 4977 | + | |
| 4978 | + | |
| 4979 | + | |
| 4980 | + | |
| 4981 | + | |
| 4982 | + | |
| 4983 | + | |
| 4984 | + | |
| 4985 | + | |
| 4986 | + | |
| 4987 | + | |
| 4988 | + | |
| 4989 | + | |
| 4990 | + | |
| 4991 | + | |
| 4992 | + | |
| 4993 | + | |
| 4994 | + | |
| 4995 | + | |
| 4996 | + | |
| 4997 | + | |
| 4998 | + | |
| 4999 | + | |
| 5000 | + | |
| 5001 | + | |
| 5002 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
0 commit comments