Skip to content

fix(compiler): reject reference calls that compile cannot replace - #1011

Merged
kvlonge merged 2 commits into
mainfrom
fix/unquoted-ref-arguments
Oct 7, 2026
Merged

kvlonge merged 2 commits into
mainfrom
fix/unquoted-ref-arguments

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Why

Extraction accepted __ref(stg_orders), __ref('stg_orders'), spaces and comments inside reference calls, but compile only replaces __ref("stg_orders"), so those models failed with misleading B002/B004/B101 errors. The docs only show the double-quoted form, so the other forms are now rejected.

Changes

  • __ref, __source, __seed, __udf, __table_fn and __dbt_ref accept exactly one double-quoted name, with nothing else inside the parentheses (__dbt_ref also takes "package", "name"). Anything else is a new P012 error, as is a __table_fn call with no argument list.
  • Each P012 points at the call's file, line and column, names the model, and shows the corrected call. One compile reports every rejected call. SQL analysis is skipped, so no B-errors appear.
  • When a macro returns the bad call, the error points at the macro and suggests @macro(__ref("name")). P006 checks of the macro's other calls still run.
  • Behaviour change: scenario and test SQL, including __assert__ CTEs, no longer accepts __ref(x), __ref('x') or spaced forms. The scenario relation rewrite now only matches the double-quoted form.
  • Both native scanners (fast path and preview tier) accept only the bare form and leave every other call to Python, so the mismatch check never fires on them. The reference cache version is bumped, and SQL containing a rejected call is never cached.
  • Message example calls use double quotes.
  • Docs cover the syntax and P012.

Verification

  • Unit, native parity and fuzz tests for every kind and form.
  • Failure-corpus cases: unquoted, commented, single-quoted, two-file, macro-returned.
  • E2E on both engines: locations and multi-file reporting.
  • cargo fmt/clippy/test --workspace --all-features with 1.98.0.
  • make compiler-differential (+ -shipped), tests/e2e/scripts/compiler_differential, make check-ci, make test.
  • Private real-project comparison against main (first commit): identical output.

@kvlonge
kvlonge enabled auto-merge (squash) October 7, 2026 19:38
Reference extraction accepted unquoted names, single-quoted names, and
whitespace or comments inside __ref(), __source(), __seed(), __udf(),
__table_fn() and __dbt_ref() calls, but compile replacement only
rewrites the double-quoted form. Those models then failed with
misleading analysis errors. Extraction now accepts exactly the
replaceable form and reports P012 with the corrected call.
Report P012 through the compile diagnostic collector with the authored
file, line, column and resource, so one compile lists every rejected
call instead of stopping at the first. Calls returned by a macro are
attributed to the macro with a pass-the-reference-in hint, and models
with a rejected call skip SQL analysis instead of adding B-errors.
Scenario relation rewriting now matches only the double-quoted form,
and example calls in messages use double quotes.

The preview-tier native reference scanner accepts only the bare
double-quoted form and defers every other call to Python, which
reports P012, so native and Python compiles stay identical and the
mismatch check never fires on rejected calls.
@kvlonge
kvlonge force-pushed the fix/unquoted-ref-arguments branch from 48cedd4 to dedb819 Compare October 7, 2026 20:41
@kvlonge
kvlonge merged commit 57c6da6 into main Oct 7, 2026
40 checks passed
@kvlonge
kvlonge deleted the fix/unquoted-ref-arguments branch October 7, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant