diff --git a/src/Type.cc b/src/Type.cc index bb67b2fbbe..f9857fe9cb 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -2673,6 +2673,31 @@ TypePtr merge_types(const TypePtr& arg_t1, const TypePtr& arg_t2) } } +TypePtr merge_type_list(detail::ListExpr* elements) + { + TypeList* tl_type = elements->GetType()->AsTypeList(); + const auto& tl = tl_type->GetTypes(); + + if ( tl.size() < 1 ) + { + reporter->Error("no type can be inferred for empty list"); + return nullptr; + } + + auto t = tl[0]; + + if ( tl.size() == 1 ) + return t; + + for ( size_t i = 1; t && i < tl.size(); ++i ) + t = merge_types(t, tl[i]); + + if ( ! t ) + reporter->Error("inconsistent types in list"); + + return t; + } + TypePtr maximal_type(detail::ListExpr* elements) { TypeList* tl_type = elements->GetType()->AsTypeList(); diff --git a/src/Type.h b/src/Type.h index d775207637..1c7b719ada 100644 --- a/src/Type.h +++ b/src/Type.h @@ -928,6 +928,12 @@ extern TypeTag max_type(TypeTag t1, TypeTag t2); // an error message) if the types are incompatible. TypePtr merge_types(const TypePtr& t1, const TypePtr& t2); +// Given a list of expressions, returns a (ref'd) type reflecting +// a merged type consistent across all of them, or nil if this +// cannot be done. +[[deprecated("Remove in v6.1. Use maximal_type() if possible. See GH-2604.")]] TypePtr +merge_type_list(detail::ListExpr* elements); + // Given a list of expressions, returns the maximal type consistent across // all of them, or nil if this cannot be done. "Maximal" incorporates // notions of arithmetic coercion, but otherwise requires type-equivalence.