@@ -785,12 +785,48 @@ func (c *Checker) someSymbolTableInScope(
785785 if table != nil && callback (table , symbolTableIDFromMembers (sym ), false , false , location ) {
786786 return true
787787 }
788+ // Class expression names (e.g., `B` in `class B {}`) are not stored in any
789+ // scope table — the binder uses bindAnonymousDeclaration. Expose the name
790+ // binding here so getAccessibleSymbolChain can resolve self-references.
791+ // This mirrors the special casing of class expression names in
792+ // (*NameResolver).Resolve; if class names are ever bound differently
793+ // (e.g., via class-local type aliases), both sites should be updated.
794+ if ast .IsClassExpression (location ) && location .AsClassExpression ().Name () != nil {
795+ nameTable := c .getClassExpressionNameTable (location )
796+ if nameTable != nil && callback (nameTable , symbolTableIDFromLocals (location .AsNode ()), false , true , location ) {
797+ return true
798+ }
799+ }
788800 }
789801 }
790802
791803 return callback (c .globals , symbolTableIDFromGlobals (), false , true , nil )
792804}
793805
806+ // getClassExpressionNameTable returns a cached symbol table containing the class
807+ // expression's name binding. Class expression names are bound via
808+ // bindAnonymousDeclaration and aren't stored in any container's locals, so this
809+ // synthesized table lets someSymbolTableInScope expose them during accessibility checks.
810+ func (c * Checker ) getClassExpressionNameTable (location * ast.Node ) ast.SymbolTable {
811+ nodeId := ast .GetNodeId (location )
812+ if c .classExpressionNameTables != nil {
813+ if table , ok := c .classExpressionNameTables [nodeId ]; ok {
814+ return table
815+ }
816+ }
817+ classSymbol := c .getSymbolOfDeclaration (location )
818+ nameText := location .AsClassExpression ().Name ().Text ()
819+ if len (nameText ) == 0 || classSymbol == nil {
820+ return nil
821+ }
822+ table := ast.SymbolTable {nameText : classSymbol }
823+ if c .classExpressionNameTables == nil {
824+ c .classExpressionNameTables = make (map [ast.NodeId ]ast.SymbolTable )
825+ }
826+ c .classExpressionNameTables [nodeId ] = table
827+ return table
828+ }
829+
794830/**
795831 * Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested
796832 *
0 commit comments