Ver código fonte

Do not error when interface is implemented by a base

Ensure the following scenario works:

1. contract b has method f1
2. contract c has b as a base and interface with f1

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 4 anos atrás
pai
commit
e1086b8d6e
2 arquivos alterados com 27 adições e 1 exclusões
  1. 1 1
      src/sema/contracts.rs
  2. 26 0
      tests/substrate_tests/inheritance.rs

+ 1 - 1
src/sema/contracts.rs

@@ -629,7 +629,7 @@ fn layout_contract(contract_no: usize, ns: &mut ast::Namespace) {
                             ));
                             continue;
                         }
-                    } else {
+                    } else if cur.has_body {
                         if let Some(entry) = override_needed.get_mut(&signature) {
                             entry.push((base_contract_no, function_no));
                         } else {

+ 26 - 0
tests/substrate_tests/inheritance.rs

@@ -303,6 +303,32 @@ fn test_interface() {
         first_error(ns.diagnostics),
         "interface ‘bar’ is not allowed to have contract variable ‘x’"
     );
+
+    // 1. implementing an interface does not require an override
+
+    // 2. interface is function implemented by base
+    let ns = parse_and_resolve(
+        r#"
+        interface bar {
+            function f1(address a) external;
+        }
+
+        interface bar2 {
+            function f1(address a) external;
+        }
+
+        contract x is bar {
+            function f1(address a) public {}
+        }
+
+        contract y is bar2, x {
+            function f2(address a) public {}
+        }
+        "#,
+        Target::Substrate,
+    );
+
+    no_errors(ns.diagnostics);
 }
 
 #[test]