浏览代码

Using for not permitted in interfaces (#1302)

* Using for not permitted in interfaces
* @solana/web3.js now requires node 16

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 2 年之前
父节点
当前提交
e219b6bf97
共有 4 个文件被更改,包括 30 次插入10 次删除
  1. 4 4
      .github/workflows/test.yml
  2. 10 0
      src/sema/using.rs
  3. 8 0
      tests/contract_testcases/solana/using_interface.sol
  4. 8 6
      tests/evm.rs

+ 4 - 4
.github/workflows/test.yml

@@ -223,7 +223,7 @@ jobs:
       uses: actions/checkout@v3
     - uses: actions/setup-node@v3
       with:
-        node-version: '14'
+        node-version: '16'
     - name: Rust Stable
       run: rustup default stable
     - name: Setup yarn
@@ -270,7 +270,7 @@ jobs:
       uses: actions/checkout@v3
     - uses: actions/setup-node@v3
       with:
-        node-version: '14'
+        node-version: '16'
     - name: Rust Stable
       run: rustup default stable
     - uses: actions/download-artifact@v3
@@ -308,7 +308,7 @@ jobs:
       id: substrate
     - uses: actions/setup-node@v3
       with:
-        node-version: '14'
+        node-version: '16'
     - uses: actions/download-artifact@v3
       with:
         name: solang-linux-x86-64
@@ -348,7 +348,7 @@ jobs:
     - name: Install Node.js
       uses: actions/setup-node@v3
       with:
-        node-version: '14'
+        node-version: '16'
     - run: npm install
       working-directory: ./vscode
     - run: npm run compile

+ 10 - 0
src/sema/using.rs

@@ -23,6 +23,16 @@ pub(crate) fn using_decl(
 ) -> Result<Using, ()> {
     let mut diagnostics = Diagnostics::default();
 
+    if let Some(contract_no) = contract_no {
+        if ns.contracts[contract_no].is_interface() {
+            ns.diagnostics.push(Diagnostic::error(
+                using.loc,
+                "using for not permitted in interface".into(),
+            ));
+            return Err(());
+        }
+    }
+
     let ty = if let Some(expr) = &using.ty {
         match ns.resolve_type(file_no, contract_no, false, expr, &mut diagnostics) {
             Ok(Type::Contract(contract_no)) if ns.contracts[contract_no].is_library() => {

+ 8 - 0
tests/contract_testcases/solana/using_interface.sol

@@ -0,0 +1,8 @@
+function double(int x) pure returns (int) { return x * 2; }
+
+interface C {
+	using {double} for int;
+}
+
+// ---- Expect: diagnostics ----
+// error: 4:2-24: using for not permitted in interface

+ 8 - 6
tests/evm.rs

@@ -171,7 +171,7 @@ contract testing  {
 
 #[test]
 fn ethereum_solidity_tests() {
-    let error_matcher = regex::Regex::new(r"// ----\r?\n// \w+Error( \d+)?:").unwrap();
+    let error_matcher = regex::Regex::new(r"// ----\r?\n// \w+Error( \d+)?: (.*)").unwrap();
 
     let entries = WalkDir::new(
         Path::new(env!("CARGO_MANIFEST_DIR"))
@@ -209,7 +209,9 @@ fn ethereum_solidity_tests() {
 
             let source = fs::read_to_string(entry.path()).unwrap();
 
-            let expect_error = error_matcher.is_match(&source);
+            let expect_error = error_matcher
+                .captures(&source)
+                .map(|captures| captures.get(2).unwrap().as_str());
 
             let (mut cache, names) = set_file_contents(&source, path);
 
@@ -221,7 +223,7 @@ fn ethereum_solidity_tests() {
                     let ns = parse_and_resolve(OsStr::new(&name), &mut cache, Target::EVM);
 
                     if ns.diagnostics.any_errors() {
-                        if !expect_error {
+                        if expect_error.is_none() {
                             println!("file: {}", entry.path().display());
 
                             ns.print_diagnostics_in_plain(&cache, false);
@@ -230,10 +232,10 @@ fn ethereum_solidity_tests() {
                         } else {
                             0
                         }
-                    } else if expect_error {
+                    } else if let Some(error) = expect_error {
                         println!("file: {}", entry.path().display());
 
-                        println!("expecting error, none found");
+                        println!("expecting error {error}");
 
                         1
                     } else {
@@ -246,7 +248,7 @@ fn ethereum_solidity_tests() {
         })
         .sum();
 
-    assert_eq!(errors, 1085);
+    assert_eq!(errors, 1084);
 }
 
 fn set_file_contents(source: &str, path: &Path) -> (FileResolver, Vec<String>) {