diff -r ed17822e7662 libinterp/parse-tree/profiler.cc
--- a/libinterp/parse-tree/profiler.cc	Sat Jan 01 19:43:52 2022 -0800
+++ b/libinterp/parse-tree/profiler.cc	Sun Jan 02 14:05:48 2022 -0500
@@ -52,7 +52,8 @@
     for (const auto& nm : list)
       retval(i++) = nm;
 
-    assert (i == n);
+    if (i != n)
+      panic_impossible ();
 
     return retval;
   }
@@ -108,7 +109,9 @@
         entry.m_time += m_time;
         entry.m_calls += m_calls;
 
-        assert (m_parent);
+        if (! m_parent)
+          panic_impossible ();
+
         if (m_parent->m_fcn_id != 0)
           {
             entry.m_parents.insert (m_parent->m_fcn_id);
@@ -162,7 +165,8 @@
 
         ++i;
       }
-    assert (i == n);
+    if (i != n)
+      panic_impossible ();
 
     octave_map retval;
 
@@ -196,8 +200,8 @@
   profiler::enter_function (const std::string& fcn)
   {
     // The enter class will check and only call us if the profiler is active.
-    assert (enabled ());
-    assert (m_call_tree);
+    if (! enabled() || ! m_call_tree)
+      panic_impossible ();
 
     // If there is already an active function, add to its time before
     // pushing the new one.
@@ -230,7 +234,8 @@
   {
     if (m_active_fcn)
       {
-        assert (m_call_tree);
+        if (! m_call_tree)
+          panic_impossible ();
         // FIXME: This assert statements doesn't make sense if profile() is
         // called from within a function hierarchy to begin with.  See bug
         // #39587.
diff -r ed17822e7662 libinterp/parse-tree/pt-classdef.cc
--- a/libinterp/parse-tree/pt-classdef.cc	Sat Jan 01 19:43:52 2022 -0800
+++ b/libinterp/parse-tree/pt-classdef.cc	Sun Jan 02 14:05:48 2022 -0500
@@ -64,7 +64,8 @@
 
         octave_function *f = tmp.function_value (true);
 
-        assert (f);
+        if (! f)
+          panic_impossible ();
 
         return f->call (tw, nargout);
       }
diff -r ed17822e7662 libinterp/parse-tree/pt-eval.cc
--- a/libinterp/parse-tree/pt-eval.cc	Sat Jan 01 19:43:52 2022 -0800
+++ b/libinterp/parse-tree/pt-eval.cc	Sun Jan 02 14:05:48 2022 -0500
@@ -3480,7 +3480,8 @@
 
         if (user_function.is_special_expr ())
           {
-            assert (cmd_list->length () == 1);
+            if (cmd_list->length () != 1)
+              panic_impossible ();
 
             tree_statement *stmt = cmd_list->front ();
 
diff -r ed17822e7662 libinterp/parse-tree/pt-idx.cc
--- a/libinterp/parse-tree/pt-idx.cc	Sat Jan 01 19:43:52 2022 -0800
+++ b/libinterp/parse-tree/pt-idx.cc	Sun Jan 02 14:05:48 2022 -0500
@@ -346,7 +346,8 @@
   {
     octave_value_list retval;
 
-    assert (! m_args.empty ());
+    if (m_args.empty ())
+      panic_impossible ();
 
     auto p_args = m_args.begin ();
     auto p_arg_nm = m_arg_nm.begin ();
diff -r ed17822e7662 libinterp/parse-tree/pt-pr-code.cc
--- a/libinterp/parse-tree/pt-pr-code.cc	Sat Jan 01 19:43:52 2022 -0800
+++ b/libinterp/parse-tree/pt-pr-code.cc	Sun Jan 02 14:05:48 2022 -0500
@@ -1203,7 +1203,8 @@
   void
   tree_print_code::indent (void)
   {
-    assert (m_curr_print_indent_level >= 0);
+    if (m_curr_print_indent_level < 0)
+      panic_impossible ();
 
     if (m_beginning_of_line)
       {
diff -r ed17822e7662 libinterp/parse-tree/pt-tm-const.cc
--- a/libinterp/parse-tree/pt-tm-const.cc	Sat Jan 01 19:43:52 2022 -0800
+++ b/libinterp/parse-tree/pt-tm-const.cc	Sun Jan 02 14:05:48 2022 -0500
@@ -608,7 +608,8 @@
           {
             // Optimize all scalars case.
             TYPE result (m_dv);
-            assert (static_cast<std::size_t> (result.numel ()) == row.length ());
+            if (static_cast<std::size_t> (result.numel ()) != row.length ())
+              panic_impossible ();
             octave_idx_type i = 0;
             for (const auto& elt : row)
               result(i++) = octave_value_extract<ELT_T> (elt);
diff -r ed17822e7662 libinterp/parse-tree/token.cc
--- a/libinterp/parse-tree/token.cc	Sat Jan 01 19:43:52 2022 -0800
+++ b/libinterp/parse-tree/token.cc	Sun Jan 02 14:05:48 2022 -0500
@@ -29,6 +29,7 @@
 
 #include <cassert>
 
+#include "error.h"
 #include "token.h"
 
 namespace octave
@@ -95,14 +96,16 @@
   std::string
   token::text (void) const
   {
-    assert (m_type_tag == string_token);
+    if (m_type_tag != string_token)
+      panic_impossible ();
     return *m_tok_info.m_str;
   }
 
   octave_value
   token::number (void) const
   {
-    assert (m_type_tag == numeric_token);
+    if (m_type_tag != numeric_token)
+      panic_impossible ();
     return *m_tok_info.m_num;
   }
 
@@ -115,21 +118,24 @@
   token::end_tok_type
   token::ettype (void) const
   {
-    assert (m_type_tag == ettype_token);
+    if (m_type_tag != ettype_token)
+      panic_impossible ();
     return m_tok_info.m_et;
   }
 
   std::string
   token::superclass_method_name (void) const
   {
-    assert (m_type_tag == scls_name_token);
+    if (m_type_tag != scls_name_token)
+      panic_impossible ();
     return m_tok_info.m_superclass_info->m_method_name;
   }
 
   std::string
   token::superclass_class_name (void) const
   {
-    assert (m_type_tag == scls_name_token);
+    if (m_type_tag != scls_name_token)
+      panic_impossible ();
     return m_tok_info.m_superclass_info->m_class_name;
   }
 
