Skip to content

import: keep Dang's names out of schema imports - #275

Merged
vito merged 2 commits into
mainfrom
schema-values-over-builtins
Nov 9, 2026
Merged

vito merged 2 commits into
mainfrom
schema-values-over-builtins

Conversation

@vito

@vito vito commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

A schema import's namespace (Test.…) now holds only what the schema itself defines. Dang's own builtins and prelude are no longer re-exported through it.

Problem

The namespace used to hold Dang's builtins and prelude alongside the schema's names:

  • Type checking: TypeScopeFromSchema fell back to the prelude, so Test.Path, Test.Random, Test.Regexp and the codec namespaces resolved through the import.
  • Runtime: ValueScopeFromSchema bound the builtins into the import's value scope after the schema's values. A builtin therefore overwrote a schema binding with the same name. With a Query field named toString, Test.toString(value: 7) type-checked as the schema's field but ran Dang's toString and returned "7".

Change

The import's namespace now holds only:

  • The schema's types, including GraphQL's built-in scalars (ID, String, Int, Float, Boolean), which every schema has. The schema's type scope falls back to just those five scalars instead of the prelude.
  • Its Query fields.
  • Its directives.

ValueScopeFromSchema binds no builtins. So Test.toString is the schema's field when the schema has one and an error otherwise, and Test.Path is an error.

The errors read:

  • field "print" not found in Test
  • field "Path" not found in Test
  • type "Regexp" not found in Test, for type annotations

A small separate commit makes every unresolved qualified type name its namespace: type "X" not found in Ns instead of unresolved type: X.

Unchanged:

  • Unqualified names resolve as before.
  • Imports still never shadow a builtin unqualified, so bare toString is Dang's.
  • Qualified GraphQL scalars (Test.String) still work.
  • A schema scalar named like a codec still gets encode/decode grafted on: Dagger.JSON.encode works.

Out of scope: native Dang module imports ([imports.Lib] path = …) still expose the prelude and builtins (Lib.toString, Lib.Path). The same rule applies to them, but fixing it needs a different mechanism.

What relied on the old behavior

I found nothing that reads builtins or prelude names through an import's namespace.

  • History: the builtins have been bound into the import value scope since it was introduced (NewEvalEnvWithSchema, before 98c8135).
  • Embedders and tools: I checked the Dagger SDK (core/sdk/dang, which only passes ImportConfigs), the REPL and the docs tools (BuildScopesFromImports), the LSP, and directory mode (evaluateDirectoryFiles). In each, unqualified builtins come from the importing scope (NewValueScope / NewPreludeTypeScope), never from the import.
  • Source code: a grep over Dang's tests, docs and skills, and over dagger/dagger's .dang files, found no qualified use of a prelude or builtin name through a schema import. The only Lib.toString / Lib.loop uses are native-module imports of the module's own pub functions.
  • Go tests: the one Go test whose error text changed is TestRunDirDeclarationShadowsImportAlias, which now expects the new qualified message.

Tests

  • The test server (tests/gqlserver) gains toString(value: Int!): String!, which returns "schema toString: <n>". generated.go is regenerated.
  • tests/test_import_namespace.dang:
    • Test.toString(value: 7) reaches the server's field. This failed on main with left: "7".
    • Unqualified toString(7) is still the builtin.
    • Test.String / Int / Float / Boolean resolve.
  • New error goldens:
    • import_qualified_prelude_type covers Test.Path("a/b").
    • import_qualified_builtin covers Test.print("hello"), a builtin the schema lacks.
    • import_qualified_prelude_type_annotation covers let pattern: Test.Regexp! = ….
  • Docs: the GraphQL modules page and the dang-language skill state the namespace rule.

Maintainer decisions

  • An import's namespace holds only what the imported schema defines: its types (with GraphQL's built-in scalars), Query fields and directives. Dang's builtins and prelude are reached unqualified, never through an import.
  • Native Dang module imports get the same rule (only pub declarations), built with a different mechanism.

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

vito added 2 commits November 9, 2026 05:25
An unresolved qualified type now says where it was looked up:
`type "Container" not found in Dagger` rather than `unresolved type:
Container`, which read as if the name had been looked up unqualified.

Signed-off-by: Alex Suraci <[email protected]>
A schema import's namespace held Dang's builtins and prelude next to the
schema's own names: its type scope fell back to the prelude, and its value
scope had the builtins bound into it, after the schema's values. So
`Test.Path` and `Test.Random` resolved, and `Test.toString`, where the schema
has a toString field, type-checked as the field but ran the builtin.

Now the namespace holds only what the schema defines: its types (with
GraphQL's built-in scalars, which every schema has), Query fields and
directives. The type scope falls back to just ID/String/Int/Float/Boolean,
and ValueScopeFromSchema binds no builtins. Builtins are reached unqualified,
where imports still never shadow them. Nothing read builtins through the
import's value scope: unqualified names resolve in the importing scope.

The test server gains a `toString(value: Int!): String!` field to cover it.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the schema-values-over-builtins branch from 91bab76 to 55312dc Compare November 9, 2026 14:14
@vito vito changed the title eval: let schema values win over builtins import: keep Dang's names out of schema imports Nov 9, 2026
@vito
vito added this pull request to stack #280 November 9, 2026 15:11
@vito
vito merged commit fb3d3a2 into main Nov 9, 2026
9 checks passed
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