Repository navigation
fix: SqlHandler.AppendLiteral expects a constant (#109) - #163
Merged
Merged
Conversation
… build checks it The handler is public because the compiler builds it in the contributor's assembly, so AppendLiteral could be called by hand with any string, which then reached the DDL as it was. Nothing can stop that call; its parameter is now [ConstantExpected], so a string built at run time is CA1857, a warning in a contributor's build by default and an error here. The kernel probes run the SDK's .NET analyzers, so E11 compiles a hand-built handler fed a runtime string and asserts CA1857 beside the interpolated form. PublicSurfaceTests holds the attribute. CLAUDE.md and the API design say the guarantee is the holes', not the handler's. Closes #109 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #109
Problem
SqlHandleris public, as an interpolated-string handler has to be: the compiler builds it in the contributor's assembly. So a contributor could build one by hand, callAppendLiteralwith a string built at run time, and pass it tosql.Statement(ref handler). The string reached the DDL as it was, past the typed holes. Reproduced before the fix: probeE11(below) compiled clean against the kernel, with the SDK's .NET analyzers on.Change
AppendLiteral's parameter is[ConstantExpected]. A value that is not a constant is CA1857: a warning in a contributor's build by default, an error in this repository's. The compiler only ever passes constants, sosql.Statement($"…")is unchanged.string.Interngets around it, and it depends on how the runtime interns strings. The remarks,CLAUDE.mdanddesign/schemakit-api.mdnow say the guarantee comes from the holes, not the handler.SchemaSqlTests' helper drives the handler by hand on purpose, so it now suppresses CA1857 with a reason.Tests
KernelProbeTestsnow runs the SDK's .NET analyzers. The project file copies them next to the tests, so each snippet is compiled the way a contributor's build compiles it. New probeE11.literal-from-a-runtime-string: a hand-built handler fed"DROP INDEX " + namemust fail with CA1857, and its allowed twin, the interpolated form, must compile clean. Without the attribute the forbidden form compiled clean (1 failed, 54 passed). With it, all 127 probe tests pass, and the existing allowed forms stay clean with the analyzers on.PublicSurfaceTests.The_handler_takes_a_constant_for_a_literalchecks that the attribute is there. It fails with the attribute removed.🤖 Generated with Claude Code