Repro
Minimal:
import SyntaxKit
let _ = Group {
if true {
Struct("A") { Variable(.let, name: "x", type: "Int") }
}
}
Compile (or interpret via swift Repro.swift) against SyntaxKit:
error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
let _ = Group {
^
Expected
The CodeBlockBuilderResult declares both forks of buildEither and buildOptional (Sources/SyntaxKit/CodeBlocks/CodeBlockBuilderResult.swift:46-58), so the API surface advertises support for if/else inside Group { … }. The expectation is that the conditional contributes (or not) a Struct to the group like any other CodeBlock.
Actual
The Swift compiler bails on type inference with error: failed to produce diagnostic for expression — a type-checker timeout / failed solver, not a useful diagnostic. The body compiles fine when the if is removed.
Notes
- Reproduces on Swift 6.x / macOS, both in
swift script mode and swiftc compile mode.
- The variadic
buildBlock(_ components: any CodeBlock...) overload combined with buildEither overload resolution is the most likely culprit — both EmptyCodeBlock-typed branches and concrete CodeBlock branches need to unify through the existential any CodeBlock.
- No test under
Tests/SyntaxKitTests/Unit/ exercises an if inside Group { … }, which is why this hasn't been caught.
Surfaced from
Issue #154 — POC step 1 for a SyntaxKit-driven codegen CLI. See Docs/research/poc-step1-results.md §4. Not blocking that work, but blocks users who want to write conditional codegen.
Repro
Minimal:
Compile (or interpret via
swift Repro.swift) against SyntaxKit:Expected
The
CodeBlockBuilderResultdeclares both forks ofbuildEitherandbuildOptional(Sources/SyntaxKit/CodeBlocks/CodeBlockBuilderResult.swift:46-58), so the API surface advertises support forif/elseinsideGroup { … }. The expectation is that the conditional contributes (or not) aStructto the group like any otherCodeBlock.Actual
The Swift compiler bails on type inference with
error: failed to produce diagnostic for expression— a type-checker timeout / failed solver, not a useful diagnostic. The body compiles fine when theifis removed.Notes
swiftscript mode andswiftccompile mode.buildBlock(_ components: any CodeBlock...)overload combined withbuildEitheroverload resolution is the most likely culprit — bothEmptyCodeBlock-typed branches and concreteCodeBlockbranches need to unify through the existentialany CodeBlock.Tests/SyntaxKitTests/Unit/exercises anifinsideGroup { … }, which is why this hasn't been caught.Surfaced from
Issue #154 — POC step 1 for a SyntaxKit-driven codegen CLI. See
Docs/research/poc-step1-results.md§4. Not blocking that work, but blocks users who want to write conditional codegen.