style_lint: add STYLE031 (table insert run → table literal), revive dead STYLE021#3115
Merged
Merged
Conversation
…dead STYLE021 STYLE031 is the table twin of STYLE012: an empty table<K;V> (or table<K> set) declaration followed by >= 2 contiguous `t |> insert(k, v)` / `t[k] = v` statements collapses to a table (set) literal move-assign. Computed keys are allowed (runtime-duplicate is last-wins in both forms); runs with a duplicate CONST key stay silent since a literal rejects them at compile time (error 30706) while sequential inserts overwrite. While wiring the STYLE021 handoff (JV tables with const keys keep the stronger JV((k1=...)) suggestion), the new test exposed that STYLE021 had been dead code since landing: its type check matched a tHandle "JsonValue" annotation, but JsonValue is a das struct (daslib/json.das). Fixed the match (tPointer -> tStructure, name + module json) and added the missing style021 test; computed-key JV runs now fall through to STYLE031. Tree sweep: rewrote 6 fixture tables to literals (linq source fixture, long_length, with_boost x2, serialization + data_walker tutorials), nolint'd 12 sites where insert/[]= is the machinery under test (fused tab[k]=v opcodes, packed WithHash nodes, dapi layout, value-key API, insert-teaching tutorials). Touched files also cleaned of pre-existing STYLE001/STYLE028/LINT003/LINT013 warnings. Docs: lint.rst STYLE031 section + STYLE021 fall-through note, skill table rows for 029/030 (were missing) and 031, CLAUDE.md idiom row, module docstring lines for STYLE023 (was missing) and STYLE031. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new style-lint rule (STYLE031) to collapse “empty table + contiguous insert/[]= run” into a table/set literal move-assign, and fixes STYLE021 so it correctly detects table<string; JsonValue?> insert-runs and hands off to STYLE031 for computed-key cases. The PR also updates docs, adds targeted lint-rule tests, and refreshes several tutorials/tests to either use literals or explicitly suppress the new lint where incremental insertion is the point.
Changes:
- Implement STYLE031 in
daslib/style_lint.das, including duplicate-const-key suppression and STYLE021 handoff. - Revive STYLE021 by correcting its JsonValue type match and adding regression tests for STYLE021/STYLE031 division of labor.
- Sweep affected fixtures/tutorials/tests: rewrite eligible insert-runs to literals and add
nolintannotations where insert/[]= behavior is under test or being taught; update docs/skills tables accordingly.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| utils/lint/tests/style031_table_insert_run.das | New rule test coverage for STYLE031 across map/set/[]=/mixed/computed-key and JV-handoff scenarios. |
| utils/lint/tests/style021_jv_table_insert.das | New regression test ensuring STYLE021 fires for const-key JV table runs and computed-key runs fall through to STYLE031. |
| tutorials/language/47_data_walker.das | Removes self-> noise (STYLE028) and replaces a simple table build with a literal. |
| tutorials/language/41_serialization.das | Rewrites table initialization sequence into a table literal. |
| tutorials/language/30_json.das | Adds nolint:STYLE021 to keep incremental-building tutorial example intact. |
| tutorials/language/10_tables.das | Adds nolint:STYLE031 to preserve insert-API teaching example. |
| tests/with_boost/test_with_table.das | Rewrites contiguous insert-run into a literal to satisfy STYLE031. |
| tests/with_boost/test_with_lock_panics.das | Renames unused with_ binders and rewrites one insert-run into a literal. |
| tests/table_packed/test_packed.das | Adds nolint:STYLE031 where packed-table insert path is the subject under test. |
| tests/table_packed/test_packed_constkey.das | Adds nolint:STYLE031 in const-key insert/[]=-path tests. |
| tests/long_array_table/test_long_length.das | Rewrites a simple table build into a literal. |
| tests/long_array_table/test_fusion_table_i64.das | Adds nolint:STYLE031 where fused tab[k]=v write path is under test. |
| tests/long_array_table/test_dapi_layout.das | Adds nolint:STYLE031 where canonical insert layout behavior is under test. |
| tests/linq/test_linq_table_source.das | Rewrites table factory function to return a table literal. |
| tests/language/test_value_table_key.das | Adds nolint:STYLE031 and updates table get callback callsites to the modern $(...) form. |
| skills/style_lint.md | Documents STYLE031, updates STYLE021 description (including the handoff behavior), and adds missing STYLE029/STYLE030 rows. |
| doc/source/reference/language/lint.rst | Documents STYLE031 and clarifies STYLE021 computed-key fall-through to STYLE031. |
| daslib/style_lint.das | Core implementation: revive STYLE021 type match and add new STYLE031 detection and messaging. |
| CLAUDE.md | Adds STYLE031 to the style-lint idiom migration table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
STYLE031 — table insert run → table literal
The table twin of STYLE012: an empty
table<K;V>(ortable<K>set) declaration followed by ≥ 2 contiguoust |> insert(k, v)/t[k] = vstatements collapses to a table (set) literal move-assign:Semantics probed before writing the rule:
error[30706]), so the rewrite would not compile. Type-tagged const-key comparison covers string/int/uint/int64/uint64/float/double/bool/enum keys.insertrejects non-copyable values (error[31400]), so every run the lint can see is literal-compatible — no emplace special-casing needed.insert+[]=) and exact-arity matching (3-arg map, 2-arg set; the positional array overloads can't leak in).STYLE021 was dead code — revived
Wiring the STYLE031↔STYLE021 handoff (JV tables with const keys should keep the stronger
JV((k1=..., k2=...))suggestion) exposed that STYLE021 never fired since landing: its type check matched atHandleannotation named "JsonValue", butJsonValueis a das struct (daslib/json.das). It also had no test. Fixed the match (tPointer→tStructure, name + modulejson) and added the missingstyle021_jv_table_insert.dastest pinning both the rule and the handoff. Computed-key JV runs now fall through to STYLE031.Tree sweep (19 hits)
return <- { ... }), long_length, with_boost ×2, serialization + data_walker tutorials.[]=is the machinery under test: fusedtab[k]=vopcodes, packed-table WithHash nodes, dapi layout, value-key table API, and the two tutorials that deliberately teach the insert API. (The fused-overwrite test has duplicate const keys and was already correctly skipped by the dup guard.)self->pad(in the data-walker tutorial).Docs
lint.rst: STYLE031 section + STYLE021 fall-through noteskills/style_lint.md: rows for 031 and the previously missing 029/030; STYLE021 row correctedCLAUDE.md: idiom-table row; module docstring gained the missing STYLE023 lineValidation
Preflight full tier: 16 passed, 0 failed (cpp-syntax skipped — no C++ changes), including sphinx-latex/html + pdflatex, tests-interp/jit/aot, and sequence smoke. 43/43 lint-rule tests, 190/190 runtime tests in touched dirs, tree re-sweep zero remaining hits, detect-dupe clean on the new functions.
🤖 Generated with Claude Code