@@ -1813,15 +1813,34 @@ TExprNode::TPtr BuildDictOverList(TPositionHandle pos, const TExprNode::TPtr& co
1813
1813
1814
1814
TExprNode::TPtr BuildDictOverTuple(TExprNode::TPtr&& collection, const TTypeAnnotationNode*& dictKeyType, TExprContext& ctx)
1815
1815
{
1816
- if (!collection->GetTypeAnn()->Cast<TTupleExprType>()->GetSize()) {
1816
+ const auto pos = collection->Pos();
1817
+ const auto tupleType = collection->GetTypeAnn()->Cast<TTupleExprType>();
1818
+ if (!tupleType->GetSize()) {
1817
1819
dictKeyType = nullptr;
1818
1820
return nullptr;
1819
1821
}
1822
+ TTypeAnnotationNode::TListType types(tupleType->GetItems());
1823
+ dictKeyType = CommonType(pos, types, ctx);
1824
+ YQL_ENSURE(dictKeyType, "Uncompatible collection elements.");
1820
1825
1821
- dictKeyType = CommonTypeForChildren(*collection, ctx);
1822
- YQL_ENSURE(dictKeyType, "Uncompatible colllection elements.");
1823
- const auto pos = collection->Pos();
1824
- return ctx.NewCallable(pos, "DictFromKeys", {ExpandType(pos, *dictKeyType, ctx), std::move(collection)});
1826
+ TExprNode::TPtr tuple;
1827
+ if (collection->IsList()) {
1828
+ tuple = collection;
1829
+ } else {
1830
+ TExprNode::TListType items;
1831
+ items.reserve(tupleType->GetSize());
1832
+ for (size_t i = 0; i != tupleType->GetSize(); ++i) {
1833
+ items.push_back(
1834
+ ctx.NewCallable(
1835
+ pos,
1836
+ "Nth",
1837
+ {collection, ctx.NewAtom(pos, ui32(i))}
1838
+ )
1839
+ );
1840
+ }
1841
+ tuple = ctx.NewList(pos, std::move(items));
1842
+ }
1843
+ return ctx.NewCallable(pos, "DictFromKeys", {ExpandType(pos, *dictKeyType, ctx), std::move(tuple)});
1825
1844
}
1826
1845
1827
1846
TExprNode::TPtr ExpandSqlIn(const TExprNode::TPtr& input, TExprContext& ctx) {
0 commit comments