Skip to content

Fix crash when global augmentations resolve pattern ambient modules with import attributes - #64857

Open
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:andarist/pattern-module-global-augmentation-crash
Open

Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:andarist/pattern-module-global-augmentation-crash

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes a crash reported here: #64851 (comment)

A declare global augmentation that merges into an alias can make the checker resolve a module while it’s still setting up, before global types (such as Object) exist. Picking the matching pattern ambient module compares attribute types with isTypeAssignableTo (and other relationship checking functions) but that can fall back to reading Object's properties and since that doesn't exist at that point - the compiler crashes.

Given the compiler doesn't make it easy to only compare own properties, I decided to just "emulate" that by iterating through properties with skipObjectFunctionPropertyAugment. This short-circuits the problem - but it's also just more spec-correct (those attribute "objects" dont inherit from Object). Even in the case of dynamic import() when we actually see real objects, the spec ignores the inherited properties cause passing the received object through EnumerableOwnProperties

Copilot AI balanced review requested due to automatic review settings October 18, 2026 15:10
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 18, 2026
@typescript-automation

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

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.

🟡 Changes recommended

The new matcher accepts partial union properties as required attributes, which can select the wrong ambient module.

1 open issue
What changed in this PR

Fixes a compiler initialization crash when global augmentations resolve pattern ambient modules with import attributes.

Changes:

  • Replaces general attribute-object comparisons with property-based matching.
  • Adds regression tests for global augmentation, Object members, and dynamic-import attributes.
  • Adds expected diagnostic, type, and symbol baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​patternAmbientModuleImportAttributesIgnoreObjectMembers.ts Tests ignoring global Object members.
tsc/​testdata/​tests/​cases/​compiler/​importAttributeDynamicImportsUndefined.ts Tests dynamic-import attribute variants.
tsc/​testdata/​tests/​cases/​compiler/​globalAugmentationResolvingAliasToPatternAmbientModuleWithAttributes2.ts Tests attributed resolution during augmentation.
tsc/​testdata/​tests/​cases/​compiler/​globalAugmentationResolvingAliasToPatternAmbientModuleWithAttributes.ts Reproduces the initialization crash.
tsc/​testdata/​baselines/​reference/​compiler/​patternAmbientModuleImportAttributesIgnoreObjectMembers.types Records attribute-selection types.
tsc/​testdata/​baselines/​reference/​compiler/​patternAmbientModuleImportAttributesIgnoreObjectMembers.symbols Records attribute-selection symbols.
tsc/​testdata/​baselines/​reference/​compiler/​patternAmbientModuleImportAttributesIgnoreObjectMembers.errors.txt Records missing-attribute diagnostics.
tsc/​testdata/​baselines/​reference/​compiler/​importAttributeDynamicImportsUndefined.types Records dynamic-import types.
tsc/​testdata/​baselines/​reference/​compiler/​importAttributeDynamicImportsUndefined.symbols Records dynamic-import symbols.
tsc/​testdata/​baselines/​reference/​compiler/​importAttributeDynamicImportsUndefined.errors.txt Records undefined-attribute diagnostics.
tsc/​testdata/​baselines/​reference/​compiler/​globalAugmentationResolvingAliasToPatternAmbientModuleWithAttributes2.types Records successful augmentation types.
tsc/​testdata/​baselines/​reference/​compiler/​globalAugmentationResolvingAliasToPatternAmbientModuleWithAttributes2.symbols Records merged augmentation symbols.
tsc/​testdata/​baselines/​reference/​compiler/​globalAugmentationResolvingAliasToPatternAmbientModuleWithAttributes.types Records crash-regression types.
tsc/​testdata/​baselines/​reference/​compiler/​globalAugmentationResolvingAliasToPatternAmbientModuleWithAttributes.symbols Records crash-regression symbols.
tsc/​testdata/​baselines/​reference/​compiler/​globalAugmentationResolvingAliasToPatternAmbientModuleWithAttributes.errors.txt Records unresolved-module diagnostics.
tsc/​internal/​checker/​checker.go Adds specialized import-attribute comparisons.

Review effort: Balanced

}
for _, targetProp := range c.getPropertiesOfType(target) {
sourceProp := c.getPropertyOfTypeEx(source, targetProp.Name(), true /*skipObjectFunctionPropertyAugment*/, false /*includeTypeOnlyMembers*/)
if sourceProp == nil || sourceProp.Flags()&ast.SymbolFlagsOptional != 0 || !c.isTypeAssignableTo(c.getTypeOfSymbol(sourceProp), c.getTypeOfSymbol(targetProp)) {

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants