* The routine nested in the calling routine, or in one around it, that a * bare name there names (`procedure Inner;` between `procedure TFoo.Bar;` * and its `begin`, `TFoo::Bar::Inner`): the innermost one declared above the * call, the calling routine itself among them, or declared `forward` abov
(lower: string, ref: UnresolvedRef, context: ResolutionContext)
| 355 | * unit. Null when none is. |
| 356 | */ |
| 357 | function nestedRoutineInScope(lower: string, ref: UnresolvedRef, context: ResolutionContext): Found | null { |
| 358 | // Most names no nested routine has: settled before any other lookup. |
| 359 | const named = pascalNamed(lower, context); |
| 360 | if (!named.some((n) => n.kind === 'function' && n.qualifiedName.includes('::'))) return null; |
| 361 | const memo = memos(context).nestedInScope; |
| 362 | const key = `${ref.fromNodeId}|${lower}`; |
| 363 | if (memo.has(key)) return memo.get(key)!; |
| 364 | let found: Found | null = null; |
| 365 | const caller = routineNode(ref.fromNodeId, context); |
| 366 | if (caller && caller.language === 'pascal') { |
| 367 | const chain = caller.qualifiedName.toLowerCase(); |
| 368 | let best: Node | null = null; |
| 369 | let depth = -1; |
| 370 | for (const n of named) { |
| 371 | if (n.filePath !== caller.filePath || !isNestedRoutine(n, context)) continue; |
| 372 | if (n.startLine > ref.line && !declaredForward(n, ref.line, context)) continue; |
| 373 | const outer = ownerOf(n); |
| 374 | // Nested in the caller, or in a routine the caller is nested in. |
| 375 | if (chain !== outer && !chain.startsWith(`${outer}::`)) continue; |
| 376 | if (outer.length > depth || (outer.length === depth && n.startLine < best!.startLine)) { |
| 377 | best = n; |
| 378 | depth = outer.length; |
| 379 | } |
| 380 | } |
| 381 | if (best) found = { node: best, resolvedBy: 'exact-match', confidence: 0.95 }; |
| 382 | } |
| 383 | memo.set(key, found); |
| 384 | return found; |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Whether a routine nested in another is declared `forward` above a line |
no test coverage detected