Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ func (b *nodeBuilderImpl) tryReuseExistingNonParameterTypeNode(existing *ast.Typ
if annotationType == nil {
annotationType = b.getTypeFromTypeNode(existing, true)
}
if annotationType != nil && b.ch.isErrorType(annotationType) {
// allow "reusing" type nodes that resolve to error types
// those can't truly be reused but it prevents cascading errors in isolatedDeclarations
// for source with errors there is no guarantee to emit correct code anyway
// Since tryReuseExistingTypeNodeHelper is not yet implemented, directly return the existing node
Copy link

Copilot AI Oct 9, 2025

Choose a reason for hiding this comment

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

This comment references tryReuseExistingTypeNodeHelper being 'not yet implemented', but the function is called on line 422. The comment should be updated to accurately reflect the current state or removed if no longer relevant.

Suggested change
// Since tryReuseExistingTypeNodeHelper is not yet implemented, directly return the existing node

Copilot uses AI. Check for mistakes.

return existing
}
if annotationType != nil && b.typeNodeIsEquivalentToType(host, t, annotationType) && b.existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, t) {
result := b.tryReuseExistingTypeNodeHelper(existing)
if result != nil {
Expand Down Expand Up @@ -2006,6 +2013,15 @@ func (b *nodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati
t = b.ch.getOptionalType(t, false)
}

// Try to reuse existing type annotation if present
if declaration != nil && declaration.Type() != nil {
typeAnnotation := declaration.Type()
reused := b.tryReuseExistingTypeNode(typeAnnotation, t, declaration, addUndefinedForParameter)
if reused != nil {
return reused
}
}

restoreFlags := b.saveRestoreFlags()
if t.flags&TypeFlagsUniqueESSymbol != 0 && t.symbol == symbol && (b.ctx.enclosingDeclaration == nil || core.Some(symbol.Declarations, func(d *ast.Declaration) bool {
return ast.GetSourceFileOfNode(d) == b.ctx.enclosingFile
Expand Down

This file was deleted.

This file was deleted.

Loading