From 50d93bfc5bcd160059522e22310934ea4ecb2c57 Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Thu, 10 Feb 2022 16:21:06 -0800 Subject: [PATCH] Fix type check of `seq.nth` (#8093) The code for type checking `seq.nth` was trying to retrieve the sequence element type before ensuring that the type of the first argument was a sequence, which lead to assertion failures. This commit reorders the checks to avoid this issue. --- src/theory/strings/theory_strings_type_rules.cpp | 9 +++++---- test/regress/CMakeLists.txt | 1 + test/regress/regress0/seq/seq-nth-type-check.smt2 | 8 ++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 test/regress/regress0/seq/seq-nth-type-check.smt2 diff --git a/src/theory/strings/theory_strings_type_rules.cpp b/src/theory/strings/theory_strings_type_rules.cpp index 183344aa2..c92502c40 100644 --- a/src/theory/strings/theory_strings_type_rules.cpp +++ b/src/theory/strings/theory_strings_type_rules.cpp @@ -312,13 +312,14 @@ TypeNode SeqNthTypeRule::computeType(NodeManager* nodeManager, bool check) { TypeNode t = n[0].getType(check); + if (check && !t.isSequence()) + { + throw TypeCheckingExceptionPrivate(n, "expecting a sequence in nth"); + } + TypeNode t1 = t.getSequenceElementType(); if (check) { - if (!t.isSequence()) - { - throw TypeCheckingExceptionPrivate(n, "expecting a sequence in nth"); - } TypeNode t2 = n[1].getType(check); if (!t2.isInteger()) { diff --git a/test/regress/CMakeLists.txt b/test/regress/CMakeLists.txt index bc3880b18..c812d364e 100644 --- a/test/regress/CMakeLists.txt +++ b/test/regress/CMakeLists.txt @@ -1145,6 +1145,7 @@ set(regress_0_tests regress0/seq/seq-ex5.smt2 regress0/seq/seq-expand-defs.smt2 regress0/seq/seq-nemp.smt2 + regress0/seq/seq-nth-type-check.smt2 regress0/seq/seq-nth-uf-z.smt2 regress0/seq/seq-nth-uf.smt2 regress0/seq/seq-nth-undef-unsat.smt2 diff --git a/test/regress/regress0/seq/seq-nth-type-check.smt2 b/test/regress/regress0/seq/seq-nth-type-check.smt2 new file mode 100644 index 000000000..3e9c38e7b --- /dev/null +++ b/test/regress/regress0/seq/seq-nth-type-check.smt2 @@ -0,0 +1,8 @@ +; DISABLE-TESTER: dump +; EXPECT: expecting a sequence +; SCRUBBER: grep -o "expecting a sequence" +; EXIT: 1 +(set-logic QF_SLIA) +(declare-const i Int) +(assert (= i (seq.nth 0 i))) +(check-sat) -- 2.30.2