T0024a — Static analysis: type inference and diagnostics
Part of the roadmap. Phase 1 · wave 5 · size L.
- Depends on: T0018, T0019
- Area:
area:core - Tier hint:
risk:high: a publicanalyze()and diagnostics oncompile(), so the core tier with a second reviewer from the other vendor. - Parallel with: T0020, T0021
- Parent: T0024, split on 2026-11-12; T0024b adds strict mode on top of this task.
Goal
Levels 1 and 2 of the T0024 design notes: type and cardinality inference over the AST, the diagnostics that compile() throws and analyze() returns, and the fraction warning.
Scope
src/analysis/:inferred-type.ts(the type sets and cardinality of a value),operators.ts(the operator rules at the type level, mirroring the runtime kernels),scope.ts(the focus and the type guards in force) andanalyzer.ts(the walk, which never changes the AST and never evaluates).- Always, in
compile(): an unknown function, a wrong number of arguments, a type argument that is not a type name,$totaloutsideaggregate()(semantic/undefined-variable), and an input or argument of a type a function never accepts (semantic/type-mismatch), from the expectations the functions declare (input,expectsandscopeinfunctions/define.ts). An operator whose operands it never accepts is a warning, because the suite expects the execution error (spec notes). - With a model:
semantic/unknown-element(with ahintfor a choice element written with its type suffix), a leading type name that does not match the input (semantic/type-mismatch), andsemantic/unknown-typewarnings that keep the T0008 error timing. The type guards of the suite'sisSemanticChecksgroup (spec notes). - The
semantic/fraction-ignoredwarning, as the parent describes it (spec notes). - Internal API:
analyze(), theinputTypeoption (one type name or several, needsmodel), andcompile()throwingFhirPathSemanticErrorwith every diagnostic attached.Diagnosticgets an optionalhint. - Public API:
analyze()andAnalysisResult, model-less, designed for themodelandinputTypeoptions that T0038 adds.strictis T0024b. - The conformance runner's adapter analyzes every test with the type of its input, as the HL7 Java runner does (spec notes).
- FHIR versions: as the parent says; the cases run against the real
r4,r5andr6providers inpackages/core/test/generated-models.test.ts.
Acceptance criteria
-
name.given1andEncounter.name.givenoninputType: 'Patient'are semantic errors (teststestSimpleFail,testSimpleWithWrongContext), and so isObservation.valueQuantity.unit(testPolymorphismB, with the hintvalue.ofType(Quantity)) and(Observation.value as Period).unit(testPolymorphismAsB). - Conformance group
isSemanticCheckspasses, as do allinvalid="semantic"tests in phase 1 that do not need strict mode, in R4 and R5.testIif6andtestDollarOrderNotAllowedare T0024b. - With the real
r4,r5andr6providers, the same expression gets each version's diagnostics:Observation.triggeredByissemantic/unknown-elementunder R4 only,Observation.instantiatesunder R4 and R6, andinputType: 'DeviceAlert'is valid under R6 only. No R6 conformance result is claimed. - Analysis without a model never produces false errors for valid expressions in the suite, and with the suite's models and inputs it reports no error for an expression that evaluates (
tools/conformance/src/static-analysis.test.ts). - Unknown-type warnings leave compilation successful and produce execution errors only at evaluated use sites; model-less unqualified resource-name targets produce no unknown-type diagnostic. Known nonmatching types are not unknown-type errors.
-
analyze()reports a warning for each ignored fraction written in the expression:@1973-12-25 + 7.7 days(testPlusDate2),@T10:00 + 1.5 hours,@2014 + 23 monthsandtoday() - 7.7 days. It reports none for@1973-12-25 + 7 days, for@1973-12-25T00:00:00.000+10:00 + 0.1 's'(testPlusDate19, which keeps the fraction) or for a quantity from the input data. The warned expressions compile and evaluate to the same results as before.