From: Andrew Reynolds Date: Fri, 1 Oct 2021 21:38:15 +0000 (-0500) Subject: Fix ascription check for return types on ordinary functions (#7290) X-Git-Tag: cvc5-1.0.0~1135 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8210a5ebefd4cc0779d7968e891db5bc63dba545;p=cvc5.git Fix ascription check for return types on ordinary functions (#7290) Fixes #7274. --- diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 39b38be30..84c0bd17c 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -598,13 +598,19 @@ api::Term Parser::applyTypeAscription(api::Term t, api::Sort s) } return t; } - // otherwise, nothing to do - // check that the type is correct - if (t.getSort() != s) + // Otherwise, check that the type is correct. Type ascriptions in SMT-LIB 2.6 + // referred to the range of function sorts. Note that this is only a check + // and does not impact the returned term. + api::Sort checkSort = t.getSort(); + if (checkSort.isFunction()) + { + checkSort = checkSort.getFunctionCodomainSort(); + } + if (checkSort != s) { std::stringstream ss; - ss << "Type ascription not satisfied, term " << t << " expected sort " << s - << " but has sort " << t.getSort(); + ss << "Type ascription not satisfied, term " << t + << " expected (codomain) sort " << s << " but has sort " << t.getSort(); parseError(ss.str()); } return t; diff --git a/test/regress/CMakeLists.txt b/test/regress/CMakeLists.txt index 3bfe356fa..768fe852f 100644 --- a/test/regress/CMakeLists.txt +++ b/test/regress/CMakeLists.txt @@ -779,6 +779,7 @@ set(regress_0_tests regress0/parser/force_logic_set_logic.smt2 regress0/parser/force_logic_success.smt2 regress0/parser/issue5163.smt2 + regress0/parser/issue7274.smt2 regress0/parser/linear_arithmetic_err1.smt2 regress0/parser/linear_arithmetic_err2.smt2 regress0/parser/linear_arithmetic_err3.smt2 diff --git a/test/regress/regress0/parser/issue7274.smt2 b/test/regress/regress0/parser/issue7274.smt2 new file mode 100644 index 000000000..c7a38d078 --- /dev/null +++ b/test/regress/regress0/parser/issue7274.smt2 @@ -0,0 +1,7 @@ +(set-logic ALL) +(set-info :status sat) +(declare-fun f (Int) Int) +(declare-fun g1 (Int) Int) +(declare-fun x () Int) +(assert (= ((as f Int) x) (g1 x))) +(check-sat)