From: Andrew Reynolds Date: Fri, 3 Dec 2021 18:38:40 +0000 (-0600) Subject: Check constructor is used in APPLY_CONSTRUCTOR (#7737) X-Git-Tag: cvc5-1.0.0~730 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cb60e1af03cbe10cc46f401645836142f6d9fd3b;p=cvc5.git Check constructor is used in APPLY_CONSTRUCTOR (#7737) Fixes cvc5/cvc5-projects#373. --- diff --git a/src/theory/datatypes/theory_datatypes_type_rules.cpp b/src/theory/datatypes/theory_datatypes_type_rules.cpp index 86a11357b..d3c06d1f3 100644 --- a/src/theory/datatypes/theory_datatypes_type_rules.cpp +++ b/src/theory/datatypes/theory_datatypes_type_rules.cpp @@ -36,6 +36,10 @@ TypeNode DatatypeConstructorTypeRule::computeType(NodeManager* nodeManager, { Assert(n.getKind() == kind::APPLY_CONSTRUCTOR); TypeNode consType = n.getOperator().getType(check); + if (!consType.isConstructor()) + { + throw TypeCheckingExceptionPrivate(n, "expected constructor to apply"); + } TypeNode t = consType.getConstructorRangeType(); Assert(t.isDatatype()); TNode::iterator child_it = n.begin(); diff --git a/test/unit/api/cpp/solver_black.cpp b/test/unit/api/cpp/solver_black.cpp index 66a35a1af..0f6e2759c 100644 --- a/test/unit/api/cpp/solver_black.cpp +++ b/test/unit/api/cpp/solver_black.cpp @@ -2642,6 +2642,25 @@ TEST_F(TestApiBlackSolver, issue5893) ASSERT_NO_FATAL_FAILURE(distinct.getOp()); } +TEST_F(TestApiBlackSolver, proj_issue373) +{ + Sort s1 = d_solver.getRealSort(); + + DatatypeConstructorDecl ctor13 = d_solver.mkDatatypeConstructorDecl("_x115"); + ctor13.addSelector("_x109", s1); + Sort s4 = d_solver.declareDatatype("_x86", {ctor13}); + + Term t452 = d_solver.mkVar(s1, "_x281"); + Term bvl = d_solver.mkTerm(d_solver.mkOp(VARIABLE_LIST), {t452}); + Term acons = + d_solver.mkTerm(d_solver.mkOp(APPLY_CONSTRUCTOR), + {s4.getDatatype().getConstructorTerm("_x115"), t452}); + // type exception + ASSERT_THROW( + d_solver.mkTerm(d_solver.mkOp(APPLY_CONSTRUCTOR), {bvl, acons, t452}), + CVC5ApiException); +} + TEST_F(TestApiBlackSolver, doubleUseCons) { DatatypeConstructorDecl ctor1 = d_solver.mkDatatypeConstructorDecl("_x21");