Skip to content

Fix two checker diagnostics found while dogfooding - #309

Merged
vito merged 2 commits into
mainfrom
dogfood-diagnostic-fixes
Nov 13, 2026
Merged

vito merged 2 commits into
mainfrom
dogfood-diagnostic-fixes

Conversation

@vito

@vito vito commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Two checker/diagnostic bugs found while dogfooding, one commit each.

1. GraphQL object list hints suggested 1.x selection syntax

The hints for selecting from (or calling a list method on) a GraphQL object list suggested value.{id}. In 2.x that's a dot-block, so following the hint literally gave a syntax error. They now say value.{{id}}, worded like the existing case-pattern hint (ast_patterns.go). I also fixed comments and doc comments that still showed single-brace selections and inline-fragment bodies.

Before:

Error: cannot call list method "length" directly on a GraphQL object list; select fields first, e.g. value.{id}.length

After:

Error: cannot call list method "length" directly on a GraphQL object list; select fields on its elements first, e.g. value.{{id}}.length
Error: cannot select "name" from a GraphQL object list; select fields on its elements first, e.g. value.{{id}}

New golden: select_on_graphql_object_list.

2. Failed declarations no longer cascade

When let c = <bad> failed in a block, a lambda or a function body, every later use reported "c" not found. At the top level the binding fell back to a fresh type variable, so uses failed with internal errors about a type it never had.

A failed declaration now binds its name to poisonType. Reading it, as a name or as a member through self/a type, fails with a poisonedError. InferenceErrors.Add keeps that as a failure without reporting it, so the reading expression fails quietly and a declaration that reads it is poisoned in turn. The original error is reported once, and unrelated errors are still reported.

When the declaration itself gives the name a type, the name keeps that type, so its uses are still checked against it. That covers an annotation, a function's declared signature (including block-local functions) and a type's hoisted constructor. A REPL entry that fails now restores what it redefined and removes what it declared, so a poisoned name never outlives the entry.

Before:

Error: "undefinedThing" not found     (let e = undefinedThing, in a block)
Error: "e" not found                  (e + 1)

Error: operator addition is not defined between types Int! and String!   (let c = 1 + "x")
Error: Select.Infer: expected NonNullType or TypeScope, got hm.TypeVariable   (c.foo)
Error: FunCall.Infer: expected function, got a (hm.TypeVariable)              (c(1))
Error: cannot index non-collection type a                                     (c[0])
... one per use

After: only the original errors (failed_declaration_does_not_cascade.golden):

2 inference errors:
Error 1: operator addition is not defined between types Int! and String!
Error 2: "undefinedThing" not found

Two existing goldens lost their cascaded errors: flow_sensitive_null_else_branch (a Select.Infer ... hm.TypeVariable error) and narrowing_invalidated_nested_param_call (a "g" not found error).

Tests: the TestFailedDeclarationsDontCascade table (poison_test.go) covers top-level, block, lambda, function-body, nested-function, type-field, self and annotation cases, plus cases where independent errors must still be reported. TestReplFailedEntryDeclaresNothing covers the REPL.

Notes for review:

  • The poisoned type prints as unknown. <error> broke Neovim omni-completion of nearby names in TestLSP.
  • .agents/skills/testing/SKILL.md gets a short section on the mechanism, because a new error collector that bypasses InferenceErrors would leak "c" failed to type-check.
  • Out of scope, and unchanged: a type's method body can't read an unannotated computed top-level let at all, because the types phase runs before the variables phase. It reports "not found" whether or not the let failed.
  • If an unannotated pub field's initializer fails, the type has no constructor signature, so the type's name is poisoned. That's on purpose: there's no signature to check uses against.

Checks: all Go test packages (including TestLSP), fmt/stale, docs, test/nocgo and go generate staleness for every package pass.

vito added 2 commits November 13, 2026 01:49
The diagnostics for selecting from or calling a list method on a GraphQL
object list suggested `value.{id}`, the Dang 1.x selection syntax. In 2.x
that is a dot-block, so following the hint gave a syntax error. Suggest
`value.{{id}}` like the case-pattern hint already does, with the same
wording, and cover the select variant with a golden test.

Also refresh comments that still described selection (and inline fragment
bodies) with single braces.

Signed-off-by: Alex Suraci <[email protected]>
When `let c = <expr that fails to type-check>` failed in a block, a lambda
or a function body, every later use of `c` also reported `"c" not found`.
At the top level the binding fell back to a fresh type variable instead,
which turned uses into errors about a type it never had (`Select.Infer:
expected NonNullType or TypeScope, got hm.TypeVariable`).

A failed declaration now binds its name to poisonType, at the top level and
in blocks. Reading it (as a name, or a member through `self` or a type)
fails with a poisonedError that InferenceErrors keeps as a failure without
reporting, so the expression fails quietly, a declaration reading it is
poisoned in turn, and only the original error is reported. Unrelated errors
around it still are.

A name the declaration gives a type itself keeps it, so its uses are still
checked: an annotation, a function's declared signature (block-local
functions included), or a type's hoisted constructor. A REPL entry that
fails restores what it redefined and takes back what it declared, so a
poisoned name never outlives it.

The poisoned type shows as `unknown` in hover and completion: `<error>`
broke Neovim's completion of nearby names.

Signed-off-by: Alex Suraci <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Deploying dang with  Cloudflare Pages  Cloudflare Pages

Latest commit: df051bc
Status: ✅  Deploy successful!
Preview URL: https://0980c3c0.dang-3kk.pages.dev
Branch Preview URL: https://dogfood-diagnostic-fixes.dang-3kk.pages.dev

View logs

@vito
vito force-pushed the dogfood-diagnostic-fixes branch from 9cf374f to df051bc Compare November 13, 2026 03:19
@vito vito changed the title Fix three checker diagnostics found while dogfooding Fix two checker diagnostics found while dogfooding Nov 13, 2026
@vito
vito merged commit 1a658bc into main Nov 13, 2026
9 of 11 checks passed
vito added a commit to dagger/dagger that referenced this pull request Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to
WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs
cgo anywhere, and its highlighter (dang.Highlight) is usable from any
binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list
hints suggest `value.{{id}}`, and a failed declaration no longer cascades
"not found" errors through its uses.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit to dagger/dagger that referenced this pull request Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to
WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs
cgo anywhere, and its highlighter (dang.Highlight) is usable from any
binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list
hints suggest `value.{{id}}`, and a failed declaration no longer cascades
"not found" errors through its uses.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit to dagger/dagger that referenced this pull request Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to
WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs
cgo anywhere, and its highlighter (dang.Highlight) is usable from any
binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list
hints suggest `value.{{id}}`, and a failed declaration no longer cascades
"not found" errors through its uses.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Nov 13, 2026
Hints for common mistakes get a section, with two errors as printed.
Faster Dagger modules, failed declarations reported once and the GraphQL
object list hint join the smaller changes. Go embedders learn that Dang no
longer needs cgo, and about LoadTreeSitter. The lede and sources cover
them, verified at 2918064.

Signed-off-by: Alex Suraci <[email protected]>
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