Repository: aptos-labs/aptos-core (language: python)

Issue:
[Bug][move-compiler-v2] #[expected_failure] with invalid location yields no error in V2
# 🐛 Bug

See test output
- third_party/move/move-compiler/tests/move_check/unit_test/other_failures_invalid_location.unit_test.exp
- third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.exp
Note that V1 shows errors for lines 26, 30, 34, 38, such as:
```
error[E10003]: invalid attribute value
   ┌─ tests/move_check/unit_test/other_failures_invalid_location.move:26:38
   │
26 │     #[expected_failure(vector_error, location=x)]
   │                                      ^^^^^^^^^^
   │                                      │        │
   │                                      │        Expected a module identifier, e.g. 'std::vector'
   │                                      Invalid value in attribute assignment
```
Compiler V2 misses these errors.






Discussion / hints:
This issue is stale because it has been open 45 days with no activity. Remove the `stale` label or comment - otherwise this will be closed in 15 days.

Fix patch:
diff --git a/third_party/move/move-compiler-v2/src/plan_builder.rs b/third_party/move/move-compiler-v2/src/plan_builder.rs
index 804ba329bd0a4..b03c91c712938 100644
--- a/third_party/move/move-compiler-v2/src/plan_builder.rs
+++ b/third_party/move/move-compiler-v2/src/plan_builder.rs
@@ -503,9 +503,16 @@ fn get_assigned_attribute(
 fn convert_location(env: &GlobalEnv, attr: Attribute) -> Option<ModuleId> {
     let (loc, value) = get_assigned_attribute(env, TestingAttribute::ERROR_LOCATION, attr)?;
     match value {
-        AttributeValue::Name(id, opt_module_name, _sym) => {
+        AttributeValue::Name(id, opt_module_name, sym) => {
             let vloc = env.get_node_loc(id);
-            convert_module_id(env, vloc, opt_module_name)
+            let module_id_opt = convert_module_id(env, vloc.clone(), opt_module_name);
+            if !sym.display(env.symbol_pool()).to_string().is_empty() || module_id_opt.is_none() {
+                env.error_with_labels(&loc, "invalid attribute value", vec![(
+                    vloc,
+                    "Expected a module identifier, e.g. 'std::vector'".to_string(),
+                )]);
+            }
+            module_id_opt
         },
         AttributeValue::Value(id, _val) => {
             let vloc = env.get_node_loc(id);


Test patch:
diff --git a/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.exp b/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.exp
index 5697666500681..133de995f34f7 100644
--- a/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.exp
+++ b/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.exp
@@ -31,9 +31,33 @@ error: Expected `location` following `major_status`
    │                        ^^^^^^^^^^^^^^^^^
 
 error: invalid attribute value
-   ┌─ tests/unit_test/test/other_failures_invalid_location.move:38:59
+   ┌─ tests/unit_test/test/other_failures_invalid_location.move:26:38
    │
-38 │     #[expected_failure(major_status=4016, minor_status=0, location=0)]
+26 │     #[expected_failure(vector_error, location=x)]
+   │                                      ^^^^^^^^^^
+   │                                               │
+   │                                               Expected a module identifier, e.g. 'std::vector'
+
+error: invalid attribute value
+   ┌─ tests/unit_test/test/other_failures_invalid_location.move:30:36
+   │
+30 │     #[expected_failure(out_of_gas, location=0x1::m::t0)]
+   │                                    ^^^^^^^^^^^^^^^^^^^
+   │                                             │
+   │                                             Expected a module identifier, e.g. 'std::vector'
+
+error: invalid attribute value
+   ┌─ tests/unit_test/test/other_failures_invalid_location.move:38:43
+   │
+38 │     #[expected_failure(major_status=4004, location=self)]
+   │                                           ^^^^^^^^^^^^^
+   │                                                    │
+   │                                                    Expected a module identifier, e.g. 'std::vector'
+
+error: invalid attribute value
+   ┌─ tests/unit_test/test/other_failures_invalid_location.move:42:59
+   │
+42 │     #[expected_failure(major_status=4016, minor_status=0, location=0)]
    │                                                           ^^^^^^^^^^
    │                                                                    │
    │                                                                    Expected a module identifier, e.g. 'std::vector'
diff --git a/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.move b/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.move
index 786652248169f..93bfcf8a4b695 100644
--- a/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.move
+++ b/third_party/move/move-compiler-v2/tests/unit_test/test/other_failures_invalid_location.move
@@ -30,6 +30,10 @@ module 0x1::m {
     #[expected_failure(out_of_gas, location=0x1::m::t0)]
     fun u2() { }
 
+    #[test]
+    #[expected_failure(out_of_gas, location=0x1::m)]
+    fun u2_correct() { }
+
     #[test]
     #[expected_failure(major_status=4004, location=self)]
     fun u3() { }