瀏覽代碼

Fix for loop without condition or next

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 4 年之前
父節點
當前提交
cee73beb26
共有 2 個文件被更改,包括 22 次插入3 次删除
  1. 2 2
      src/codegen/statements.rs
  2. 20 1
      tests/substrate_tests/loops.rs

+ 2 - 2
src/codegen/statements.rs

@@ -283,9 +283,9 @@ pub fn statement(
             loops.leave_scope();
             loops.leave_scope();
 
 
             if body_reachable {
             if body_reachable {
-                if !next.is_empty() {
-                    cfg.set_basic_block(next_block);
+                cfg.set_basic_block(next_block);
 
 
+                if !next.is_empty() {
                     for stmt in next {
                     for stmt in next {
                         statement(
                         statement(
                             stmt,
                             stmt,

+ 20 - 1
tests/substrate_tests/loops.rs

@@ -1,4 +1,5 @@
-use crate::{first_error, parse_and_resolve};
+use crate::{build_solidity, first_error, parse_and_resolve};
+use parity_scale_codec::Encode;
 use solang::Target;
 use solang::Target;
 
 
 #[test]
 #[test]
@@ -19,3 +20,21 @@ fn test_infinite_loop() {
 
 
     assert_eq!(first_error(ns.diagnostics), "unreachable statement");
     assert_eq!(first_error(ns.diagnostics), "unreachable statement");
 }
 }
+
+#[test]
+fn for_loop_no_cond_or_next() {
+    let mut runtime = build_solidity(
+        r##"
+        contract test {
+            function foo(bool x) public {
+                for (;;) {
+                    if (x)
+                        break;
+                }
+            }
+        }"##,
+    );
+
+    runtime.constructor(0, Vec::new());
+    runtime.function("foo", true.encode());
+}