Skip to content

fix(analyzer): source checkers read analyzeExpression() options - #149

Merged
fjsj merged 4 commits into
mainfrom
fjsj/source-checkers-ignore-analyzeexpression-options
Nov 6, 2026
Merged

fjsj merged 4 commits into
mainfrom
fjsj/source-checkers-ignore-analyzeexpression-options

Conversation

@fjsj

@fjsj fjsj commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Fixes #148.

The ESLint rule, the fhirpath-check source pass, and the playground read the options of analyzeExpression() and analyzeExpressionDetailed() calls, as they read an engine call's options. They also read the functions option of analyzer and engine calls.

import { analyzeExpression, analyzeExpressionDetailed } from 'fhirpath-ts/analyzer'

analyzeExpression('%a', { variables: { a: {} } })                        // no diagnostic
analyzeExpression('%b', { env: { b: 1 } })                               // no diagnostic
analyzeExpression('%c', { vars: { c: '1' } })                            // no diagnostic
analyzeExpressionDetailed('%f', { inputType: 'Patient', env: { e: 1 } }) // unknown-variable %f
analyzeExpression('%v', { vars: { v: '%typo' } })                        // no diagnostic: vars bodies are not reported
analyzeExpression('%a', { inputType: 'Patient', ...options })            // no diagnostic: the names are not visible

analyzeExpression('hostFn()', { functions: { hostFn: {} } })             // no diagnostic
analyzeExpression('otherFn()', { functions: { hostFn: {} } })            // unknown-function otherFn
analyzeExpression('otherFn()', { functions: hostFunctions })             // no diagnostic: the names are not visible

Changes

  • CallSitePolicy.options (src/analyzer/expression-policy.ts) gives the options argument and its type, EvaluateOptions or AnalyzeOptions. One ANALYZER_CALL policy serves both analyzer calls.
  • For AnalyzeOptions, optionScopes() also reads variables. Its names are declared untyped and win over an env/vars type of the same name, as in the analyzer. A spread, a computed key, or a non-literal object leaves the names open, so an unresolved %name is not an error.
  • An analyzer call's vars expressions are not checked, since the analyzer does not report their diagnostics. An analyzer call does not inherit the engines' default varTypes in fhirpath-check, since it never sees them at runtime.
  • optionScopes() reads the names of a call's functions option. A named function is declared with any arity and replaces an engine function of the same name, as at runtime. When the source cannot read the option (a variable or a spread), the site is checked with the call's own names only and an unknown function is not reported.
  • analyzeSite checks variables at a declared-root site when the site read its call's own options. So analyzeExpression('%typo', { inputType: 'Patient' }) reports unknown-variable, which is what the call returns. A fhirpath(expr, 'Patient') site still does not, because its expression runs elsewhere.
  • docs/static-checking.md and CHANGELOG.md describe the new behavior.

Tests

  • Walker parity corpus (src/analyzer/expression-policy.test.ts): variables, env, vars, varTypes, vars bodies, open options, variables over a typed env, the functions option, and open functions.
  • src/cli/fhirpath-check.test.ts, through the CLI: an analyzer call does not get the engine's default varTypes, and a call that may replace the engine's functions drops their declarations.

Each new test fails without its fix.

Check Result
pnpm typecheck pass
pnpm lint pass
pnpm test pass
pnpm check:fhirpath pass
pnpm coverage pass
pnpm build pass
pnpm check:package pass

🤖 Generated with Claude Code

fjsj added 4 commits November 6, 2026 15:03
The ESLint rule, fhirpath-check source pass, and playground read the
env/envTypes/vars/varTypes and variables options of analyzeExpression()
and analyzeExpressionDetailed() calls, so names declared there no longer
report unknown-variable. Fixes #148.
…erit no engine varTypes

- CallSitePolicy.options { arg, type: 'EvaluateOptions' | 'AnalyzeOptions' }
  replaces optionsArg, optionsExpressions, and optionsVariables.
- An AnalyzeOptions site never inherits the engine's default varTypes, so the
  CLI no longer types a 'variables' name from an engine declaration.
- CHANGELOG Unreleased entries.
…engine calls

Settled with the user: handle inline functions in this PR. Names in a
literal functions option are declared with any arity and unknown type,
and win over defaults. Options that may hold unnamed functions (a
functions variable, a spread, a non-literal options object) silence
unknown-function.
…tions

A call whose functions option the source cannot fully name may replace
any engine function, so analyzeSite analyzes it with only the call's own
function names instead of keeping stale default arities and result types.
@fjsj
fjsj merged commit aef1090 into main Nov 6, 2026
3 checks passed
@fjsj
fjsj deleted the fjsj/source-checkers-ignore-analyzeexpression-options branch November 6, 2026 22:35
@fjsj fjsj mentioned this pull request Nov 7, 2026
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.

Source checkers ignore analyzeExpression() options: declared variables report unknown-variable

1 participant