Repository navigation
Fix crash when global augmentations resolve pattern ambient modules with import attributes - #64857
Open
Mateusz Burzyński (Andarist) wants to merge 1 commit into
Conversation
…ith import attributes
Contributor
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
Contributor
There was a problem hiding this comment.
🟡 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,
Objectmembers, 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
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.

fixes a crash reported here: #64851 (comment)
A
declare globalaugmentation that merges into an alias can make the checker resolve a module while it’s still setting up, before global types (such asObject) exist. Picking the matching pattern ambient module compares attribute types withisTypeAssignableTo(and other relationship checking functions) but that can fall back to readingObject'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 fromObject). Even in the case of dynamicimport()when we actually see real objects, the spec ignores the inherited properties cause passing the received object throughEnumerableOwnProperties