Validate binary operators against each type in a union operand - #1768
Merged
Conversation
validateBinaryExpression skipped validation entirely whenever either operand was a union type, with a TODO to check each inner-type combination instead. Implement that: decompose each union and run binaryOperatorResultType over every combination, flagging an error if any combination is invalid (e.g. `x as string or integer` used in `x + "world"`). Also narrow the void/uninitialized short-circuit in binaryOperatorResultType so `=`/`<>` comparisons of a possibly-void value against invalid/dynamic remain allowed, since real per-union-member checking now exercises that path for values like `void or roAssociativeArray`. Fixes #1749 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Covers the narrowed void short-circuit added in the previous commit: = and <> against invalid/dynamic stay allowed for void, other operators and other rhs types on void remain disallowed, and uninitialized still always rejects comparisons against invalid. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Verified against brs-engine that a void call result compared with =/<> against a dynamic value or invalid, and a "void or <type>" union compared against invalid, are all valid, runnable BrightScript patterns - these should not be flagged by the type checker. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
validateBinaryExpressionskipped validation entirely whenever either operand of a binary op was a union type, per aTODOsaying it should check each inner-type combination instead. This meant something likex as string or integerused inx + "world"never got flagged, even thoughinteger + stringis invalid.binaryOperatorResultTypeover every combination, flaggingoperator-type-mismatchif any combination is invalid.binaryOperatorResultTypeso=/<>comparisons of a possibly-void value againstinvalid/dynamicremain allowed (e.g.channel = noReturn(); if channel <> invalid) — real per-union-member checking now exercises this path for types likevoid or roAssociativeArray, which previously never reached this code due to the union bypass.Fixes #1749
Test plan
x as string or integerthenx + "world")npm run test:nocover) - 4262 passing, 0 failingnpm run lintpasses🤖 Generated with Claude Code