From: NeilBrown Date: Sat, 18 May 2019 13:51:24 +0000 (+1000) Subject: oceani: fix merging of conditionally-scoped variables. X-Git-Tag: JamisonCreek-3~4 X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=1ca9cccf579ea6d70d09c837e317aaed64a9f988 oceani: fix merging of conditionally-scoped variables. The problem here was that the list seen in ->in_scope includes more than just what is currently in-scope. It also contains things that have been replaced by new instances of the name. These can be detected a they aren't the first variable listed under their name any more. Signed-off-by: NeilBrown --- diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 42505ce..102c957 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -163,6 +163,27 @@ Now some contants are there 5 ? 3.14159 I like Pie but The cake is a lie +Test merging of variables from multiple cases + +###### test list + oceani_tests += varmerge + +###### test: varmerge + + program: + for i:=0; then i=i+1; while i < 5: + switch i + case 0: num:="zero" + case 1: num:="one" + case 2: num:="two" + case 3: num:="three" + else: num:="many" + print num,", ", + print + +###### output: varmerge + zero , one , two , three , many , + ## Conditions and Loops Now we need to test if/else and some different loops diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 1cf84ed..6b43096 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -1172,7 +1172,7 @@ all pending-scope variables become conditionally scoped. switch (v ? v->scope : OutScope) { case OutScope: case PendingScope: - /* Signal an error - once that is possible */ + /* Caller will report the error */ return NULL; case CondScope: /* All CondScope variables of this name need to be merged @@ -1193,14 +1193,14 @@ all pending-scope variables become conditionally scoped. static void var_block_close(struct parse_context *c, enum closetype ct) { - /* close of all variables that are in_scope */ + /* Close off all variables that are in_scope */ struct variable *v, **vp, *v2; scope_pop(c); for (vp = &c->in_scope; v = *vp, v && v->depth > c->scope_depth && v->min_depth > c->scope_depth; ) { - switch (ct) { + if (v->name->var == v) switch (ct) { case CloseElse: case CloseParallel: /* handle PendingScope */ switch(v->scope) { @@ -1261,7 +1261,7 @@ all pending-scope variables become conditionally scoped. } break; } - if (v->scope == OutScope) + if (v->scope == OutScope || v->name->var != v) *vp = v->in_scope; else vp = &v->in_scope;