Skip to content

Report TS1518 for all negated Unicode-set union operands - #4832

Open
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-issue-63718-manifest
Open

Report TS1518 for all negated Unicode-set union operands#4832
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-issue-63718-manifest

Conversation

Copilot AI commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Negated v-mode character classes only checked the first union operand for string matching. Operand order could therefore determine whether invalid regex syntax produced TS1518.

  • Scanner
    • Accumulate MayContainStrings across each union operand.
    • Report TS1518 when any later operand in a negated union may match multiple characters.
const a = /[^\q{xy}b]/v; // TS1518
const b = /[^b\q{xy}]/v; // TS1518
  • Coverage
    • Add a compiler regression case for both operand orders.
    • Accept updated regularExpressionScanning divergence baselines.

Copilot AI and others added 5 commits August 5, 2026 17:38
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Unicode-set scanning so TS1518 is reported regardless of negated union operand order.

Changes:

  • Accumulates MayContainStrings across union operands.
  • Reports TS1518 for later string-matching operands.
  • Adds regression coverage and updates baselines.
Show a summary per file
File Description
internal/scanner/regexp.go Accumulates and diagnoses string-matching operands.
testdata/tests/cases/compiler/negatedUnicodeSetUnionMayContainStrings.ts Tests both operand orders.
testdata/submoduleAccepted.txt Registers accepted baseline divergences.
testdata/baselines/reference/submoduleAccepted/compiler/regularExpressionScanning(target=es2015).errors.txt.diff Records ES2015 diagnostic divergence.
testdata/baselines/reference/submoduleAccepted/compiler/regularExpressionScanning(target=esnext).errors.txt.diff Records ESNext diagnostic divergence.
testdata/baselines/reference/submodule/compiler/regularExpressionScanning(target=es2015).errors.txt Updates ES2015 diagnostics.
testdata/baselines/reference/submodule/compiler/regularExpressionScanning(target=esnext).errors.txt Updates ESNext diagnostics.
testdata/baselines/reference/compiler/negatedUnicodeSetUnionMayContainStrings.errors.txt Captures expected TS1518 errors.
testdata/baselines/reference/compiler/negatedUnicodeSetUnionMayContainStrings.js Captures JavaScript emit.
testdata/baselines/reference/compiler/negatedUnicodeSetUnionMayContainStrings.symbols Captures symbol baseline.
testdata/baselines/reference/compiler/negatedUnicodeSetUnionMayContainStrings.types Captures type baseline.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Balanced

if isCharacterComplement && p.mayContainStrings {
p.error(diagnostics.Anything_that_would_possibly_match_more_than_a_single_character_is_invalid_inside_a_negated_character_class, start, p.pos()-start)
}
expressionMayContainStrings = expressionMayContainStrings || p.mayContainStrings

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed failing tests do in fact runtime fail

@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as ready for review August 5, 2026 19:29
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.

3 participants