diff --git a/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.exp b/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.exp index 84284a495de164..81323d3a839206 100644 --- a/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.exp +++ b/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.exp @@ -13,16 +13,16 @@ error: unsupported language construct │ ^^^^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:16:19 + ┌─ tests/checking-lang-v1/index.move:16:17 │ -16 │ assert!((&R[@0x1]).value == false, 1); - │ ^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +16 │ assert!(R[@0x1].value == false, 1); + │ ^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:38:19 + ┌─ tests/checking-lang-v1/index.move:38:17 │ -38 │ assert!((&test::Y>[@0x1]).field.value == true, 0); - │ ^^^^^^^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +38 │ assert!(test::Y>[@0x1].field.value == true, 0); + │ ^^^^^^^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct ┌─ tests/checking-lang-v1/index.move:43:22 @@ -31,10 +31,10 @@ error: unsupported language construct │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:45:19 + ┌─ tests/checking-lang-v1/index.move:45:17 │ -45 │ assert!((&Y>[addr]) .field.value == false, 1); - │ ^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +45 │ assert!(Y>[addr].field.value == false, 1); + │ ^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct ┌─ tests/checking-lang-v1/index.move:53:17 @@ -43,49 +43,49 @@ error: unsupported language construct │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:70:19 + ┌─ tests/checking-lang-v1/index.move:70:17 │ -70 │ assert!((&v[0]).field.value == true, 0); - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +70 │ assert!(v[0].field.value == true, 0); + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:71:19 + ┌─ tests/checking-lang-v1/index.move:71:17 │ -71 │ assert!((&v[1]).field.value == false, 0); - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +71 │ assert!(v[1].field.value == false, 0); + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:88:19 + ┌─ tests/checking-lang-v1/index.move:88:17 │ -88 │ assert!((&v[0]).field.value == true, 0); - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +88 │ assert!(v[0].field.value == true, 0); + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:89:19 + ┌─ tests/checking-lang-v1/index.move:89:17 │ -89 │ assert!((&v[1]).field.value == false, 0); - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +89 │ assert!(v[1].field.value == false, 0); + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:90:15 + ┌─ tests/checking-lang-v1/index.move:90:9 │ -90 │ (&mut v[0]).field.value = false; - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +90 │ v[0].field.value = false; + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:91:15 + ┌─ tests/checking-lang-v1/index.move:91:9 │ -91 │ (&mut v[1]).field.value = true; - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +91 │ v[1].field.value = true; + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:92:19 + ┌─ tests/checking-lang-v1/index.move:92:17 │ -92 │ assert!((&v[0]).field.value == false, 0); - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +92 │ assert!(v[0].field.value == false, 0); + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 error: unsupported language construct - ┌─ tests/checking-lang-v1/index.move:93:19 + ┌─ tests/checking-lang-v1/index.move:93:17 │ -93 │ assert!((&v[1]).field.value == true, 0); - │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 +93 │ assert!(v[1].field.value == true, 0); + │ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 diff --git a/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.move b/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.move index 759840087e5522..bc24338a2b93df 100644 --- a/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.move +++ b/third_party/move/move-compiler-v2/tests/checking-lang-v1/index.move @@ -13,7 +13,7 @@ module 0x42::test { fun test_resource_2() acquires R { 0x42::test::R[@0x1].value = false; - assert!((&R[@0x1]).value == false, 1); + assert!(R[@0x1].value == false, 1); } struct X has copy, drop, store { @@ -35,14 +35,14 @@ module 0x42::test { fun test_resource_3() { use 0x42::test; - assert!((&test::Y>[@0x1]).field.value == true, 0); + assert!(test::Y>[@0x1].field.value == true, 0); } fun test_resource_4() { let addr = @0x1; let y = &mut 0x42::test ::Y> [addr]; y.field.value = false; - assert!((&Y>[addr]) .field.value == false, 1); + assert!(Y>[addr].field.value == false, 1); } fun test_vector() { @@ -67,8 +67,8 @@ module 0x42::test { field: x2 }; let v = vector[y1, y2]; - assert!((&v[0]).field.value == true, 0); - assert!((&v[1]).field.value == false, 0); + assert!(v[0].field.value == true, 0); + assert!(v[1].field.value == false, 0); } fun test_vector_borrow_mut() { @@ -85,12 +85,12 @@ module 0x42::test { field: x2 }; let v = vector[y1, y2]; - assert!((&v[0]).field.value == true, 0); - assert!((&v[1]).field.value == false, 0); - (&mut v[0]).field.value = false; - (&mut v[1]).field.value = true; - assert!((&v[0]).field.value == false, 0); - assert!((&v[1]).field.value == true, 0); + assert!(v[0].field.value == true, 0); + assert!(v[1].field.value == false, 0); + v[0].field.value = false; + v[1].field.value = true; + assert!(v[0].field.value == false, 0); + assert!(v[1].field.value == true, 0); } diff --git a/third_party/move/move-model/src/builder/exp_builder.rs b/third_party/move/move-model/src/builder/exp_builder.rs index a22b5ed75827c3..c0e193f227810b 100644 --- a/third_party/move/move-model/src/builder/exp_builder.rs +++ b/third_party/move/move-model/src/builder/exp_builder.rs @@ -3470,6 +3470,8 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo } if !self.is_spec_mode() { self.check_language_version(loc, "vector indexing", LanguageVersion::V2_0); + // Translate to vector indexing in impl mode if the target is not a resource or a spec schema + // spec mode is handled in `translate_index` if call.is_none() { call = Some(self.call_to_vector_borrow_for_index_op(