From faa323cccb975069c762e950940c2e5efc225ee5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Tue, 19 Feb 2013 16:00:12 +0100
Subject: [PATCH] Compiler: Improved RUNTIME_CHECK_TYPES mode.

Avoid generating new compiler errors when running with -rt.
---
 src/language.yacc | 20 +++++++++-----------
 src/las.c         |  9 ++++++---
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/language.yacc b/src/language.yacc
index c48366159a..71a9f1586c 100644
--- a/src/language.yacc
+++ b/src/language.yacc
@@ -1026,14 +1026,12 @@ def: modifiers optional_attributes type_or_error optional_constant optional_star
 
 		/* fprintf(stderr, "Creating soft cast node for local #%d\n", e);*/
 
-		local_node = mklocalnode(e, 0);
+		local_node = mkcastnode(mixed_type_string, mklocalnode(e, 0));
 
-		/* The following is needed to go around the optimization in
-		 * mksoftcastnode().
+		/* NOTE: The cast to mixed above is needed to avoid generating
+		 *       compilation errors, as well as avoiding optimizations
+		 *       in mksoftcastnode().
 		 */
-		free_type(local_node->type);
-		copy_pike_type(local_node->type, mixed_type_string);
-
 		check_args =
 		  mknode(F_COMMA_EXPR, check_args,
 			 mksoftcastnode(Pike_compiler->compiler_frame->variable[e].type,
@@ -2927,12 +2925,12 @@ class: TOK_CLASS line_number_info optional_identifier
 		   mixed_type_string)) {
 		/* fprintf(stderr, "Creating soft cast node for local #%d\n", e);*/
 
-		/* The following is needed to go around the optimization in
-		 * mksoftcastnode().
-		 */
-		free_type(local_node->type);
-		copy_pike_type(local_node->type, mixed_type_string);
+		local_node = mkcastnode(mixed_type_string, local_node);
 
+		/* NOTE: The cast to mixed above is needed to avoid generating
+		 *       compilation errors, as well as avoiding optimizations
+		 *       in mksoftcastnode().
+		 */
 		local_node = mksoftcastnode(Pike_compiler->compiler_frame->
 					    variable[e].type, local_node);
 	      }
diff --git a/src/las.c b/src/las.c
index 7b4e1212c3..6e01e9ef21 100644
--- a/src/las.c
+++ b/src/las.c
@@ -387,9 +387,11 @@ static int check_node_type(node *n, struct pike_type *t, const char *msg)
   if (runtime_options & RUNTIME_CHECK_TYPES) {
     node *p = n->parent;
     if (CAR(p) == n) {
-      (_CAR(p) = mksoftcastnode(t, n))->parent = p;
+      (_CAR(p) = mksoftcastnode(t, mkcastnode(mixed_type_string, n)))
+	->parent = p;
     } else if (CDR(p) == n) {
-      (_CDR(p) = mksoftcastnode(t, n))->parent = p;
+      (_CDR(p) = mksoftcastnode(t, mkcastnode(mixed_type_string, n)))
+	->parent = p;
     } else {
       yywarning("Failed to find place to insert soft cast.");
     }
@@ -3416,7 +3418,8 @@ void fix_type_field(node *n)
 	    free_string(t1);
 	  }
 	  if (runtime_options & RUNTIME_CHECK_TYPES) {
-	    _CAR(n) = mksoftcastnode(CDR(n)->type, CAR(n));
+	    _CAR(n) = mksoftcastnode(CDR(n)->type,
+				     mkcastnode(mixed_type_string, CAR(n)));
 	  }
 	}
       }
-- 
GitLab