From 27a49d8412831b9ba54056ca7b44f49bea0a5e6a Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Fri, 22 Nov 2024 16:33:33 +0100 Subject: [PATCH] In Context::LookupUnqualifiedName(), early return when lexical_result is valid --- toolchain/check/context.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index 83bb60bb9c6e9..f63f5e3d9d90d 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -318,6 +318,14 @@ auto Context::LookupUnqualifiedName(Parse::NodeId node_id, auto [lexical_result, non_lexical_scopes] = scope_stack().LookupInLexicalScopes(name_id); + if (lexical_result.is_valid()) { + // A lexical scope never needs an associated specific. If there's a + // lexically enclosing generic, then it also encloses the point of use of + // the name. + return {.specific_id = SemIR::SpecificId::Invalid, + .inst_id = lexical_result}; + } + // Walk the non-lexical scopes and perform lookups into each of them. for (auto [index, lookup_scope_id, specific_id] : llvm::reverse(non_lexical_scopes)) { @@ -331,14 +339,6 @@ auto Context::LookupUnqualifiedName(Parse::NodeId node_id, } } - if (lexical_result.is_valid()) { - // A lexical scope never needs an associated specific. If there's a - // lexically enclosing generic, then it also encloses the point of use of - // the name. - return {.specific_id = SemIR::SpecificId::Invalid, - .inst_id = lexical_result}; - } - // We didn't find anything at all. if (required) { DiagnoseNameNotFound(node_id, name_id);