Skip to content

Commit

Permalink
keyof return string directly if one entry
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-police committed Sep 8, 2024
1 parent d9536ce commit c8ebe3e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Analysis/src/TypeFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,12 @@ TypeFunctionReductionResult<TypeId> keyofFunctionImpl(
for (std::string key : keys)
singletons.push_back(ctx->arena->addType(SingletonType{StringSingleton{key}}));

// If there's only one entry, we don't need a UnionType.
// We can take straight take it from the first entry
// because it was added into the type arena already.
if (singletons.size() == 1)
return {singletons.front(), false, {}, {}};

return {ctx->arena->addType(UnionType{singletons}), false, {}, {}};
}

Expand Down

0 comments on commit c8ebe3e

Please sign in to comment.