From fd127d90b9cf4c769c1fe1a9b16b811847a0eed9 Mon Sep 17 00:00:00 2001 From: Aina Niemetz Date: Tue, 7 Dec 2021 19:22:04 -0800 Subject: [PATCH] api: Fix Sort::getDatatypeArity() for non-parametric datatypes. (#7766) Fixes cvc5/cvc5-projects#380 --- src/api/cpp/cvc5.cpp | 2 +- test/unit/api/cpp/solver_black.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api/cpp/cvc5.cpp b/src/api/cpp/cvc5.cpp index 39410a4e6..e062e60ed 100644 --- a/src/api/cpp/cvc5.cpp +++ b/src/api/cpp/cvc5.cpp @@ -1763,7 +1763,7 @@ size_t Sort::getDatatypeArity() const CVC5_API_CHECK_NOT_NULL; CVC5_API_CHECK(isDatatype()) << "Not a datatype sort."; //////// all checks before this line - return d_type->getNumChildren() - 1; + return d_type->isParametricDatatype() ? d_type->getNumChildren() - 1 : 0; //////// CVC5_API_TRY_CATCH_END; } diff --git a/test/unit/api/cpp/solver_black.cpp b/test/unit/api/cpp/solver_black.cpp index 0f6e2759c..23aec2386 100644 --- a/test/unit/api/cpp/solver_black.cpp +++ b/test/unit/api/cpp/solver_black.cpp @@ -2671,5 +2671,12 @@ TEST_F(TestApiBlackSolver, doubleUseCons) CVC5ApiException); } +TEST_F(TestApiBlackSolver, getDatatypeArity) +{ + DatatypeConstructorDecl ctor1 = d_solver.mkDatatypeConstructorDecl("_x21"); + DatatypeConstructorDecl ctor2 = d_solver.mkDatatypeConstructorDecl("_x31"); + Sort s3 = d_solver.declareDatatype(std::string("_x17"), {ctor1, ctor2}); + ASSERT_EQ(s3.getDatatypeArity(), 0); +} } // namespace test } // namespace cvc5 -- 2.30.2