Skip to content
Merged
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
14 changes: 7 additions & 7 deletions internal/checker/symbolaccessibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,26 @@ func (c *Checker) getWithAlternativeContainers(container *ast.Symbol, symbol *as
}
// we potentially have a symbol which is a member of the instance side of something - look for a variable in scope with the container's type
// which may be acting like a namespace (eg, `Symbol` acts like a namespace when looking up `Symbol.toStringTag`)
var firstVariableMatch *ast.Symbol
var variableMatches []*ast.Symbol
if (meaning == ast.SymbolFlagsValue &&
container.Flags&leftMeaning == 0) &&
container.Flags&ast.SymbolFlagsType != 0 &&
c.getDeclaredTypeOfSymbol(container).flags&TypeFlagsObject != 0 {
c.someSymbolTableInScope(enclosingDeclaration, func(t ast.SymbolTable, _ symbolTableID, _ bool, _ bool, _ *ast.Node) bool {
found := false
for _, s := range t {
if s.Flags&leftMeaning != 0 && c.getTypeOfSymbol(s) == c.getDeclaredTypeOfSymbol(container) {
Comment on lines 140 to 147
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

Inside the symbol-table scan, c.getDeclaredTypeOfSymbol(container) is invoked repeatedly (both in the outer condition and again for every entry in the loop). Since this callback may end up traversing large tables (including globals), please hoist the container's declared type into a local variable once and reuse it within the closure to avoid unnecessary work.

Suggested change
if (meaning == ast.SymbolFlagsValue &&
container.Flags&leftMeaning == 0) &&
container.Flags&ast.SymbolFlagsType != 0 &&
c.getDeclaredTypeOfSymbol(container).flags&TypeFlagsObject != 0 {
c.someSymbolTableInScope(enclosingDeclaration, func(t ast.SymbolTable, _ symbolTableID, _ bool, _ bool, _ *ast.Node) bool {
found := false
for _, s := range t {
if s.Flags&leftMeaning != 0 && c.getTypeOfSymbol(s) == c.getDeclaredTypeOfSymbol(container) {
containerDeclaredType := c.getDeclaredTypeOfSymbol(container)
if (meaning == ast.SymbolFlagsValue &&
container.Flags&leftMeaning == 0) &&
container.Flags&ast.SymbolFlagsType != 0 &&
containerDeclaredType.flags&TypeFlagsObject != 0 {
c.someSymbolTableInScope(enclosingDeclaration, func(t ast.SymbolTable, _ symbolTableID, _ bool, _ bool, _ *ast.Node) bool {
found := false
for _, s := range t {
if s.Flags&leftMeaning != 0 && c.getTypeOfSymbol(s) == containerDeclaredType {

Copilot uses AI. Check for mistakes.
firstVariableMatch = s
return true
variableMatches = append(variableMatches, s)
found = true
}
}
return false
return found
})
c.sortSymbols(variableMatches)
}
Comment on lines +139 to 155
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

This change intentionally alters container selection to be deterministic (collect + sort matches), but this PR doesn't add a targeted regression test for it. Please add a minimal compiler test that creates multiple in-scope variables matching the same container type and asserts a stable/expected printback or symbol chain selection, to guard against future nondeterminism regressions.

Copilot generated this review using guidance from repository custom instructions.

var res []*ast.Symbol
if firstVariableMatch != nil {
res = append(res, firstVariableMatch)
}
res = append(res, variableMatches...)
res = append(res, additionalContainers...)
res = append(res, container)
if objectLiteralContainer != nil {
Expand Down
Loading