Fix type validator inconsistencies and improve variable error reporting#2076
Merged
curtisman merged 1 commit intomicrosoft:mainfrom Mar 26, 2026
Merged
Fix type validator inconsistencies and improve variable error reporting#2076curtisman merged 1 commit intomicrosoft:mainfrom
curtisman merged 1 commit intomicrosoft:mainfrom
Conversation
- 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
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.
Changes
Fix
+operator pass1/pass2 consistency: Changed||to&&in the+case ofderiveValueTypeImplso pass 1 type inference matches pass 2 validation semantics — both operands must be strings to inferstring.Use
formatSchemaType()in error messages: Replaced raw.typediscriminant strings withformatSchemaType()for richer, human-readable type descriptions (e.g.string | numberinstead oftype-union). Removed the redundant union-iteration branch invalidateValueTypethat duplicated logic already handled byisTypeAssignable.Pre-resolve expected type in
validateVariableAgainstSchema: Resolve the expected type and short-circuit onanybefore calling into structural validation.Add symmetric coinductive guard for type-reference cycles: The
isTypeAssignablevisited-set now guards bothinferredandexpectedtype-references, preventing infinite recursion when the expected type is self-recursive (e.g.A = string | A).Replace shallow
isTypeAssignablewith structuralvalidateInferredAgainstExpected: BothvalidateVariableTypeandvalidateVariableAgainstSchemanow use structural validation so object fields and array element types are checked, not just the top-level type discriminant.Remove dead
resolvedTypesparameter: Eliminated the unusedresolvedTypes: Map<string, SchemaTypeDefinition>parameter fromvalidateValueType,validateObjectValue,validateArrayValue, andvalidateVariableAgainstSchema.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/falseliteral types from boolean constants (blocked onactionSchemalacking boolean literal factories).