From d58f04dc62ec58ed72c00db43b80122fbdfc0925 Mon Sep 17 00:00:00 2001
From: NeilBrown <neil@brown.name>
Date: Wed, 22 Dec 2021 17:12:20 +1100
Subject: [PATCH] oceani: don't let error in one statement hides errors in
 next.

The error state from one statement is still visible in the next, which
can upset the reporting of errors.
So provide a clean error state for each new statement.

Signed-off-by: NeilBrown <neil@brown.name>
---
 csrc/oceani-tests.mdc | 4 +++-
 csrc/oceani.mdc       | 6 ++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc
index 0feb0d2..182c77c 100644
--- a/csrc/oceani-tests.mdc
+++ b/csrc/oceani-tests.mdc
@@ -917,7 +917,7 @@ various places that `type_err()` are called.
 
 	func main()
 		print "hello" ++ 5, 5 ++ "hello"
-
+		hello := "there"; print 4+hello
 		b ::= 3
 		b = b + 1
 
@@ -928,6 +928,8 @@ various places that `type_err()` are called.
 ###### output: type_err1
 	.tmp.code:3:25: error: expected string found number
 	.tmp.code:3:28: error: expected string found number
+	.tmp.code:4:34: error: expected number but variable 'hello' is string
+	.tmp.code:4:8: info: this is where 'hello' was set to string
 	.tmp.code:6:8: error: Cannot assign to a constant: b
 	.tmp.code:5:8: info: name was defined as a constant here
 	.tmp.code:8:11: error: Arithmetic returns number but Boolean expected
diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc
index d40a548..f97652d 100644
--- a/csrc/oceani.mdc
+++ b/csrc/oceani.mdc
@@ -2096,7 +2096,7 @@ stack.
 			if (v->merged != v)
 				continue;
 			if (!t)
-				continue;
+				continue;	// NOTEST
 			if (v->frame_pos >= 0)
 				continue;
 			while (done && done->scope_end < v->scope_start)
@@ -4605,7 +4605,9 @@ the common header for all reductions to use.
 		struct binode *e;
 
 		for (e = b; e; e = cast(binode, e->right)) {
-			t = propagate_types(e->left, c, perr, NULL, rules);
+			*perr |= *perr_local;
+			*perr_local = 0;
+			t = propagate_types(e->left, c, perr_local, NULL, rules);
 			if ((rules & Rboolok) && (t == Tbool || t == Tnone))
 				t = NULL;
 			if (t == Tnone && e->right)
-- 
2.43.0