Browse Source

Match solc diagnostic levels (#1586)

The following errors are warnings in solc

 - unreachable code should be warning
 - function types with parameter/return names should be warning
 - unknown assembly flags should be warnings

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 2 years ago
parent
commit
69e9d20c1f

+ 4 - 0
src/codegen/cfg.rs

@@ -1793,6 +1793,10 @@ fn function_cfg(
             None,
             opt,
         );
+
+        if !stmt.reachable() {
+            break;
+        }
     }
 
     if func.body.last().map(Statement::reachable).unwrap_or(true) {

+ 4 - 0
src/codegen/statements/mod.rs

@@ -52,6 +52,10 @@ pub(crate) fn statement(
                     return_override,
                     opt,
                 );
+
+                if !stmt.reachable() {
+                    break;
+                }
             }
         }
         Statement::VariableDecl(loc, pos, _, Some(init)) => {

+ 2 - 4
src/sema/namespace.rs

@@ -1134,11 +1134,10 @@ impl Namespace {
                         .into_iter()
                         .map(|p| {
                             if let Some(name) = p.id {
-                                diagnostics.push(Diagnostic::error(
+                                diagnostics.push(Diagnostic::warning(
                                     name.loc,
                                     "function type parameters cannot be named".to_string(),
                                 ));
-                                success = false;
                             }
                             p.ty
                         })
@@ -1148,11 +1147,10 @@ impl Namespace {
                         .into_iter()
                         .map(|p| {
                             if let Some(name) = p.id {
-                                diagnostics.push(Diagnostic::error(
+                                diagnostics.push(Diagnostic::warning(
                                     name.loc,
                                     "function type returns cannot be named".to_string(),
                                 ));
-                                success = false;
                             }
                             p.ty
                         })

+ 6 - 5
src/sema/statements.rs

@@ -423,6 +423,7 @@ fn statement(
         } => {
             symtable.enter_scope();
             let mut reachable = true;
+            let mut already_unreachable = false;
 
             let mut context = context.clone();
             context.unchecked |= *unchecked;
@@ -430,12 +431,12 @@ fn statement(
             let mut resolved_stmts = Vec::new();
 
             for stmt in statements {
-                if !reachable {
-                    ns.diagnostics.push(Diagnostic::error(
+                if !reachable && !already_unreachable {
+                    ns.diagnostics.push(Diagnostic::warning(
                         stmt.loc(),
                         "unreachable statement".to_string(),
                     ));
-                    return Err(());
+                    already_unreachable = true;
                 }
                 reachable = statement(
                     stmt,
@@ -911,7 +912,7 @@ fn statement(
                 for flag in flags {
                     if flag.string == "memory-safe" && ns.target == Target::EVM {
                         if let Some(prev) = &memory_safe {
-                            ns.diagnostics.push(Diagnostic::error_with_note(
+                            ns.diagnostics.push(Diagnostic::warning_with_note(
                                 flag.loc,
                                 format!("flag '{}' already specified", flag.string),
                                 *prev,
@@ -921,7 +922,7 @@ fn statement(
                             memory_safe = Some(flag.loc);
                         }
                     } else {
-                        ns.diagnostics.push(Diagnostic::error(
+                        ns.diagnostics.push(Diagnostic::warning(
                             flag.loc,
                             format!("flag '{}' not supported", flag.string),
                         ));

+ 2 - 2
tests/contract_testcases/evm/memory_safe.sol

@@ -9,6 +9,6 @@ library Issue1526 {
 }
 
 // ---- Expect: diagnostics ----
-// error: 5:34-39: flag 'foo' not supported
-// error: 5:41-54: flag 'memory-safe' already specified
+// warning: 5:34-39: flag 'foo' not supported
+// warning: 5:41-54: flag 'memory-safe' already specified
 // 	note 5:19-32: previous location

+ 3 - 1
tests/contract_testcases/polkadot/function_types/decls_04.sol

@@ -4,4 +4,6 @@ contract test {
             }
         }
 // ---- Expect: diagnostics ----
-// error: 3:42-43: function type returns cannot be named
+// warning: 2:13-34: function can be declared 'pure'
+// warning: 3:42-43: function type returns cannot be named
+// warning: 3:45-46: local variable 'a' is unused

+ 3 - 1
tests/contract_testcases/polkadot/function_types/decls_05.sol

@@ -4,4 +4,6 @@ contract test {
             }
         }
 // ---- Expect: diagnostics ----
-// error: 3:34-37: function type parameters cannot be named
+// warning: 2:13-34: function can be declared 'pure'
+// warning: 3:34-37: function type parameters cannot be named
+// warning: 3:54-55: local variable 'a' is unused

+ 2 - 1
tests/contract_testcases/polkadot/functions/for_forever.sol

@@ -8,4 +8,5 @@
         }
     }
 // ---- Expect: diagnostics ----
-// error: 7:13-19: unreachable statement
+// warning: 3:9-49: function can be declared 'pure'
+// warning: 7:13-19: unreachable statement

+ 2 - 1
tests/contract_testcases/polkadot/loops/test_infinite_loop.sol

@@ -9,4 +9,5 @@ contract test3 {
             }
         }
 // ---- Expect: diagnostics ----
-// error: 8:17-25: unreachable statement
+// warning: 5:13-63: function can be declared 'pure'
+// warning: 8:17-25: unreachable statement

+ 4 - 3
tests/contract_testcases/polkadot/yul/unreachable_after_asm.sol

@@ -14,6 +14,7 @@ contract testTypes {
 } 
 
 // ---- Expect: diagnostics ----
-// error: 5:19-32: flag 'memory-safe' not supported
-// error: 5:34-39: flag 'meh' not supported
-// error: 10:9-12:10: unreachable statement
+// warning: 2:5-14: storage variable 'b' has been assigned, but never read
+// warning: 5:19-32: flag 'memory-safe' not supported
+// warning: 5:34-39: flag 'meh' not supported
+// warning: 10:9-12:10: unreachable statement

+ 1 - 1
tests/contract_testcases/solana/yul/return_in_asm.sol

@@ -7,5 +7,5 @@ contract Contract {
 }
 
 // ---- Expect: diagnostics ----
-// error: 3:19-32: flag 'memory-safe' not supported
+// warning: 3:19-32: flag 'memory-safe' not supported
 // error: 4:13-25: builtin 'return' is not available for target Solana. Please, open a GitHub issue at https://github.com/hyperledger/solang/issues if there is need to support this function

+ 1 - 1
tests/evm.rs

@@ -253,7 +253,7 @@ fn ethereum_solidity_tests() {
         })
         .sum();
 
-    assert_eq!(errors, 986);
+    assert_eq!(errors, 960);
 }
 
 fn set_file_contents(source: &str, path: &Path) -> (FileResolver, Vec<String>) {