Skip to content

SqlHandler.AppendLiteral takes any string when it is called directly, past the typed holes #109

Closed

Description

@CaffeinatedCoder

Found by the pre-preview sweep of main @ 948496a (GPT's read of the kernel); read against the code, not run.

What happens

SqlHandler is public, as an interpolated-string handler has to be, with a public constructor and a public AppendLiteral(string) (SchemaSql.cs:102-120). A contributor can build one by hand, pass any string to AppendLiteral and hand it to sql.Statement(ref handler). The string reaches the DDL as it is.

CLAUDE.md and the type's own remarks say that nothing reaches the DDL unquoted is a property of the types. That holds for a hole of an interpolated string, which KernelProbeTests compiles. It does not hold for the handler called directly; SchemaSqlTests has a helper that does exactly that.

To decide, before the contract freezes at rc.1

  1. [ConstantExpected] on AppendLiteral's parameter. The compiler passes constants; a call with anything else is CA1857, which the repository's own build treats as an error and a contributor's build as a warning.
  2. Say what the guarantee is: the holes, not the handler. The remarks and CLAUDE.md then say so.

Both are compatible, and the first costs nothing.

Test

A compile probe in KernelProbeTests: handler.AppendLiteral(runtimeString) from a contributor's assembly, with its diagnostic asserted.

Activity

  1. added this to the 11.0.0 milestone on Nov 14, 2026
  2. added
    bug
    package/core
    severity/low
    area/migrations
    on Nov 14, 2026
  3. CaffeinatedCoder commented on Nov 16, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Fixed in #163 with option 1, and option 2 on top of it.

    Chosen: [ConstantExpected] on AppendLiteral's parameter. A string built at run time is CA1857: a warning in a contributor's build by default, an error here. The compiler passes constants, so sql.Statement($"…") is unchanged.

    Not chosen:

    • A handler only the compiler can build. The compiler builds the handler in the contributor's assembly, so its constructor and AppendLiteral have to be accessible there, which means a contributor can call them too.
    • Refusing a direct call at run time. The only signal is whether the argument is the interned literal, and string.Intern gets around that. It would also depend on how the runtime interns strings.

    The guarantee is now stated as the holes', not the handler's: in the handler's remarks, in CLAUDE.md ("The SQL vocabulary") and in design/schemakit-api.md.

    Reproduced and held. KernelProbeTests now runs the SDK's .NET analyzers, so each snippet is compiled the way a contributor's build compiles it. Probe E11.literal-from-a-runtime-string builds a handler by hand and feeds it "DROP INDEX " + name. Before the fix it compiled clean; with the fix it fails with CA1857, beside the interpolated form, which compiles clean. PublicSurfaceTests.The_handler_takes_a_constant_for_a_literal checks the attribute and fails without it.

  4. added a commit that references this issue on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/migrationsbugpackage/coreseverity/low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions