Prechádzať zdrojové kódy

Fix bug with calldata suffixes (#765)

Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
Lucas Steuernagel 3 rokov pred
rodič
commit
16fa8a0377
2 zmenil súbory, kde vykonal 51 pridanie a 7 odobranie
  1. 12 4
      src/sema/yul/expression.rs
  2. 39 3
      src/sema/yul/tests/expression.rs

+ 12 - 4
src/sema/yul/expression.rs

@@ -508,12 +508,20 @@ fn resolve_member_access(
             Some(StorageLocation::Calldata(_)),
             Some(StorageLocation::Calldata(_)),
             _,
             _,
         ) => {
         ) => {
-            if dims[0].is_none() && id.name != "offset" && id.name != "length" {
+            if dims.last().unwrap().is_none() && id.name != "offset" && id.name != "length" {
                 ns.diagnostics.push(Diagnostic::error(
                 ns.diagnostics.push(Diagnostic::error(
                     resolved_expr.loc(),
                     resolved_expr.loc(),
-                    "calldata variables only support \".offset\" and \".length\"".to_string(),
+                    "calldata variables only support ‘.offset‘ and ‘.length‘".to_string(),
                 ));
                 ));
                 return Err(());
                 return Err(());
+            } else if dims.last().unwrap().is_some() {
+                ns.diagnostics.push(Diagnostic::error(
+                    resolved_expr.loc(),
+                    format!(
+                        "the given expression does not support ‘.{}‘ suffixes",
+                        suffix_type.to_string()
+                    ),
+                ));
             }
             }
         }
         }
 
 
@@ -533,7 +541,7 @@ fn resolve_member_access(
             if id.name != "selector" && id.name != "address" {
             if id.name != "selector" && id.name != "address" {
                 ns.diagnostics.push(Diagnostic::error(
                 ns.diagnostics.push(Diagnostic::error(
                     id.loc,
                     id.loc,
-                    "variables of type function pointer only support \".selector\" and \".address\" suffixes".to_string()
+                    "variables of type function pointer only support ‘.selector‘ and ‘.address‘ suffixes".to_string()
                 ));
                 ));
                 return Err(());
                 return Err(());
             }
             }
@@ -544,7 +552,7 @@ fn resolve_member_access(
             if id.name != "slot" && id.name != "offset" {
             if id.name != "slot" && id.name != "offset" {
                 ns.diagnostics.push(Diagnostic::error(
                 ns.diagnostics.push(Diagnostic::error(
                     id.loc,
                     id.loc,
-                    "state variables only support \".slot\" and \".offset\"".to_string(),
+                    "state variables only support ‘.slot‘ and ‘.offset‘".to_string(),
                 ));
                 ));
                 return Err(());
                 return Err(());
             }
             }

+ 39 - 3
src/sema/yul/tests/expression.rs

@@ -1240,7 +1240,7 @@ contract testTypes {
     let ns = parse(file);
     let ns = parse(file);
     assert!(assert_message_in_diagnostics(
     assert!(assert_message_in_diagnostics(
         &ns.diagnostics,
         &ns.diagnostics,
-        r#"state variables only support ".slot" and ".offset""#
+        "state variables only support ‘.slot‘ and ‘.offset‘"
     ));
     ));
 
 
     let file = r#"
     let file = r#"
@@ -1296,7 +1296,7 @@ contract testTypes {
     let ns = parse(file);
     let ns = parse(file);
     assert!(assert_message_in_diagnostics(
     assert!(assert_message_in_diagnostics(
         &ns.diagnostics,
         &ns.diagnostics,
-        r#"variables of type function pointer only support ".selector" and ".address" suffixes"#
+        "variables of type function pointer only support ‘.selector‘ and ‘.address‘ suffixes"
     ));
     ));
 
 
     let file = r#"
     let file = r#"
@@ -1312,7 +1312,7 @@ contract testTypes {
     let ns = parse(file);
     let ns = parse(file);
     assert!(assert_message_in_diagnostics(
     assert!(assert_message_in_diagnostics(
         &ns.diagnostics,
         &ns.diagnostics,
-        r#"calldata variables only support ".offset" and ".length""#
+        "calldata variables only support ‘.offset‘ and ‘.length‘"
     ));
     ));
 
 
     let file = r#"
     let file = r#"
@@ -1524,3 +1524,39 @@ contract test {
         "yul variable ‘x‘ has never been read"
         "yul variable ‘x‘ has never been read"
     ));
     ));
 }
 }
+
+#[test]
+fn call_data_variables_error() {
+    let file = r#"
+contract testTypes {
+    function testAsm(uint[3][] calldata vl) public pure {
+        assembly {
+            {
+               let y := vl.selector
+            }
+        }
+    }
+}    "#;
+    let ns = parse(file);
+    assert!(assert_message_in_diagnostics(
+        &ns.diagnostics,
+        "calldata variables only support ‘.offset‘ and ‘.length‘"
+    ));
+
+    let file = r#"
+contract testTypes {
+    function testAsm(uint[][3] calldata vl) public pure {
+        assembly {
+            {
+               let y := vl.length
+            }
+        }
+    }
+}  "#;
+
+    let ns = parse(file);
+    assert!(assert_message_in_diagnostics(
+        &ns.diagnostics,
+        "the given expression does not support ‘.length‘ suffixes"
+    ));
+}