Skip to content

Fix type validator inconsistencies and improve variable error reporting#2076

Merged
curtisman merged 1 commit intomicrosoft:mainfrom
curtisman:fix-type-validator
Mar 26, 2026
Merged

Fix type validator inconsistencies and improve variable error reporting#2076
curtisman merged 1 commit intomicrosoft:mainfrom
curtisman:fix-type-validator

Conversation

@curtisman
Copy link
Copy Markdown
Member

Changes

  • Fix + operator pass1/pass2 consistency: Changed || to && in the + case of deriveValueTypeImpl so pass 1 type inference matches pass 2 validation semantics — both operands must be strings to infer string.

  • Use formatSchemaType() in error messages: Replaced raw .type discriminant strings with formatSchemaType() for richer, human-readable type descriptions (e.g. string | number instead of type-union). Removed the redundant union-iteration branch in validateValueType that duplicated logic already handled by isTypeAssignable.

  • Pre-resolve expected type in validateVariableAgainstSchema: Resolve the expected type and short-circuit on any before calling into structural validation.

  • Add symmetric coinductive guard for type-reference cycles: The isTypeAssignable visited-set now guards both inferred and expected type-references, preventing infinite recursion when the expected type is self-recursive (e.g. A = string | A).

  • Replace shallow isTypeAssignable with structural validateInferredAgainstExpected: Both validateVariableType and validateVariableAgainstSchema now use structural validation so object fields and array element types are checked, not just the top-level type discriminant.

  • Remove dead resolvedTypes parameter: Eliminated the unused resolvedTypes: Map<string, SchemaTypeDefinition> parameter from validateValueType, validateObjectValue, validateArrayValue, and validateVariableAgainstSchema.

  • Include variable name in validation error messages: Errors now report which variable caused the mismatch (e.g. Variable '$myVar' expected number, got string).

  • Add tests for variable name error reporting: Three new test cases verify that variable names appear in error messages for direct type mismatches, implicit variable mismatches, and nested field errors.

  • Add TODO for boolean literal type precision: Documented a future improvement to return true/false literal types from boolean constants (blocked on actionSchema lacking boolean literal factories).

- Fix + operator pass1/pass2 consistency (|| → &&)
- Use formatSchemaType() in error messages, remove redundant union iteration
- Pre-resolve expected type in validateVariableAgainstSchema
- Add symmetric coinductive guard for type-reference cycles
- Replace shallow isTypeAssignable with structural validateInferredAgainstExpected
  in validateVariableType and validateVariableAgainstSchema
- Remove dead resolvedTypes parameter from validation call chain
- Include variable name in validation error messages
- Add tests for variable name error reporting
- Add TODO for boolean literal type precision
@curtisman curtisman added this pull request to the merge queue Mar 26, 2026
Merged via the queue into microsoft:main with commit 144af73 Mar 26, 2026
13 of 15 checks passed
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.

1 participant