Repository: Konstantin8105/c4go
Pull request #303 (2019-03-06 12:20:47)

transpileSwitch: add atomic

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/303?src=pr&el=h1) Report
> Merging [#303](https://codecov.io/gh/Konstantin8105/c4go/pull/303?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/4a1c8d64ee43de67e2247f53b6e3c85680389ab3?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/303/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/303?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #303      +/-   ##
==========================================
+ Coverage   87.02%   87.02%   +<.01%     
==========================================
  Files         185      185              
  Lines       10321    10322       +1     
==========================================
+ Hits         8982     8983       +1     
  Misses        927      927              
  Partials      412      412
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/303?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/switch.go](https://codecov.io/gh/Konstantin8105/c4go/pull/303/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9zd2l0Y2guZ28=) | `90.16% <100%> (+0.05%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/303?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/303?src=pr&el=footer). Last update [4a1c8d6...821ab31](https://codecov.io/gh/Konstantin8105/c4go/pull/303?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/transpiler/switch.go b/transpiler/switch.go
index cccbfde..69abe57 100644
--- a/transpiler/switch.go
+++ b/transpiler/switch.go
@@ -39,7 +39,8 @@ func transpileSwitchStmt(n *ast.SwitchStmt, p *program.Program) (
 
 	// The condition is the expression to be evaulated against each of the
 	// cases.
-	condition, conditionType, newPre, newPost, err := transpileToExpr(n.Children()[len(n.Children())-2], p, false)
+	condition, conditionType, newPre, newPost, err := atomicOperation(
+		n.Children()[len(n.Children())-2], p)
 	if err != nil {
 		return nil, nil, nil, err
 	}


Test patch:
diff --git a/tests/switch.c b/tests/switch.c
index 2540308..cee5712 100644
--- a/tests/switch.c
+++ b/tests/switch.c
@@ -346,9 +346,27 @@ void switch_char()
     is_eq(form, 'S');
 }
 
+int value()
+{
+	return 42;
+}
+
+void switch_stat()
+{
+	int v = 15;
+	switch(v = value()) {
+	case 15:
+		fail("wrong");
+		break;
+	case 42: 
+		is_true(v == 42);
+		break;
+	}
+}
+
 int main()
 {
-    plan(29);
+    plan(30);
 
     switch_char();
     switch_bool();
@@ -371,6 +389,7 @@ int main()
     empty_switch();
     default_only_switch();
     switch_without_input();
+	switch_stat();
 
     done_testing();
 }