Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
rahxephon89 committed Jul 9, 2024
1 parent 16f59a3 commit 7ad3d51
Show file tree
Hide file tree
Showing 24 changed files with 653 additions and 376 deletions.
4 changes: 0 additions & 4 deletions third_party/move/move-command-line-common/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ impl NumericalAddress {
bytes: AccountAddress::MAX_ADDRESS,
format: NumberFormat::Hex,
};
pub const STD_ADDRESS: Self = NumericalAddress {
bytes: AccountAddress::ONE,
format: NumberFormat::Hex,
};

pub const fn new(bytes: [u8; AccountAddress::LENGTH], format: NumberFormat) -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Diagnostics:
error: value of type `test::Y<test::X<bool>>` does not have the `copy` ability
┌─ tests/ability-check/index_ability_err.move:12:17
12 │ let _ = Y<X<bool>>[addr];
│ ^^^^^^^^^^^^^^^^ reference content copied here
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module 0x42::test {

struct X<M> has copy, drop, store {
value: M
}
struct Y<T> has key, drop {
field: T
}

fun test_resource_no_copy() acquires Y {
let addr = @0x1;
let _ = Y<X<bool>>[addr];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Diagnostics:
error: resource indexing can only applied to a resource type (a struct type which has key ability)
┌─ tests/ability-check/index_ability_err_2.move:9:17
9 │ let _ = X<bool>[addr];
│ ^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module 0x42::test {

struct X<M> has copy, drop, store {
value: M
}

fun test_struct_no_resource() acquires X {
let addr = @0x1;
let _ = X<bool>[addr];
}

}
91 changes: 91 additions & 0 deletions third_party/move/move-compiler-v2/tests/checking-lang-v1/index.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

Diagnostics:
error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:11:17
11 │ assert!((test::R[@0x1]).value == true, 0);
│ ^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:15:9
15 │ 0x42::test::R[@0x1].value = false;
│ ^^^^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ 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 and beyond

error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:38:17
38 │ assert!(test::Y<X<bool>>[@0x1].field.value == true, 0);
│ ^^^^^^^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:43:22
43 │ let y = &mut 0x42::test ::Y<X<bool>> [addr];
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:45:17
45 │ assert!(Y<X<bool>>[addr].field.value == false, 1);
│ ^^^^^^^^^^^^^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:53:17
53 │ assert!(v[0].value == 2, 0);
│ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ 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 and beyond

error: unsupported language construct
┌─ 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 and beyond

error: unsupported language construct
┌─ 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 and beyond

error: unsupported language construct
┌─ 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 and beyond

error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:90:9
90 │ v[0].field.value = false;
│ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ tests/checking-lang-v1/index.move:91:9
91 │ v[1].field.value = true;
│ ^^^^ `_[_]` index operator in non-specification code only allowed in Move 2 and beyond

error: unsupported language construct
┌─ 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 and beyond

error: unsupported language construct
┌─ 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 and beyond
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ module 0x42::test {

fun test_resource_1() acquires R {
use 0x42::test;
assert!((&test::R[@0x1]).value == true, 0);
assert!((test::R[@0x1]).value == true, 0);
}

fun test_resource_2() acquires R {
let x = &mut 0x42::test::R[@0x1];
x.value = false;
assert!((&R[@0x1]).value == false, 1);
0x42::test::R[@0x1].value = false;
assert!(R[@0x1].value == false, 1);
}

struct X<M> has copy, drop, store {
Expand All @@ -36,14 +35,14 @@ module 0x42::test {

fun test_resource_3() {
use 0x42::test;
assert!((&test::Y<X<bool>>[@0x1]).field.value == true, 0);
assert!(test::Y<X<bool>>[@0x1].field.value == true, 0);
}

fun test_resource_4() {
let addr = @0x1;
let y = &mut 0x42::test ::Y<X<bool>> [addr];
y.field.value = false;
assert!((&Y<X<bool>>[addr]) .field.value == false, 1);
assert!(Y<X<bool>>[addr].field.value == false, 1);
}

fun test_vector() {
Expand All @@ -68,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() {
Expand All @@ -86,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);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@

Diagnostics:
error: unexpected token
┌─ tests/checking/typing/index_err.move:10:17
10 │ assert!((test::R[@0x1]).value == true, 0);
│ ^^^^^^^^^^^^^^^ resource indexing using `_[_]` needs to be paired with `&` or `&mut`

error: unexpected token
error: indexing can only be applied to a vector or a resource type (a struct type which has key ability)
┌─ tests/checking/typing/index_err.move:14:9
14 │ Test[@0x1];
│ ^^^^^^^^^^ index notation `_[_]` expects a resource or vector
14 │ UNUSED_Test[@0x1];
│ ^^^^^^^^^^^^^^^^^

error: unexpected token
┌─ tests/checking/typing/index_err.move:19:10
error: indexing can only be applied to a vector or a resource type (a struct type which has key ability)
┌─ tests/checking/typing/index_err.move:19:9
19 │ &test::Test[@0x1];
^^^^^^^^^^^^^^^^ index notation `_[_]` expects a resource or vector
19 │ &test::UNUSED_Test[@0x1];
│ ^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module 0x42::test {

struct R has key, drop { value: bool }

spec schema Test {
spec schema UNUSED_Test {
}

fun test_no_ref_for_resource() acquires R {
Expand All @@ -11,12 +11,12 @@ module 0x42::test {
}

fun test_no_schema() {
Test[@0x1];
UNUSED_Test[@0x1];
}

fun test_no_schema_ref() {
use 0x42::test;
&test::Test[@0x1];
&test::UNUSED_Test[@0x1];
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Diagnostics:
error: cannot pass `&X<integer>` to a function which expects argument of type `&vector<_>`
error: expected `vector<struct{value}>` but found a value of type `X<integer>`
┌─ tests/checking/typing/index_err_2.move:11:17
11 │ assert!(x[0].value == 2, 0);
│ ^^^^
│ ^
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Diagnostics:
error: Invalid operation: storage operation on type `test::Y` can only be done within the defining module `0x42::test`
┌─ tests/file-format-generator/index_acquires_err.move:14:9
14 │ fun test_resource_other_module() acquires 0x42::test::Y {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
15 │ let addr = @0x1;
16 │ assert!((&0x42::test::Y<0x42::test::X<bool>>[addr]).field.value == true, 1);
│ ------------------------------------------- called here

error: Invalid operation: access of the field `field` on type `test::Y` can only be done within the defining module `0x42::test`
┌─ tests/file-format-generator/index_acquires_err.move:14:9
14 │ fun test_resource_other_module() acquires 0x42::test::Y {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
15 │ let addr = @0x1;
16 │ assert!((&0x42::test::Y<0x42::test::X<bool>>[addr]).field.value == true, 1);
│ ------------------------------------------------- accessed here

error: Invalid operation: access of the field `value` on type `test::X` can only be done within the defining module `0x42::test`
┌─ tests/file-format-generator/index_acquires_err.move:14:9
14 │ fun test_resource_other_module() acquires 0x42::test::Y {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
15 │ let addr = @0x1;
16 │ assert!((&0x42::test::Y<0x42::test::X<bool>>[addr]).field.value == true, 1);
│ ------------------------------------------------------- accessed here
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module 0x42::test {

struct X<M> has copy, drop, store {
value: M
}
struct Y<T> has key, drop {
field: T
}

}

module 0x42::test2 {

fun test_resource_other_module() acquires 0x42::test::Y {
let addr = @0x1;
assert!((&0x42::test::Y<0x42::test::X<bool>>[addr]).field.value == true, 1);
spec {
// This is OK
assert 0x42::test::Y<0x42::test::X<bool>>[addr].field.value == true;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Diagnostics:
error: Invalid operation: storage operation on type `test::Y` can only be done within the defining module `0x42::test`
┌─ tests/file-format-generator/index_acquires_err.move:14:9
14 │ fun test_resource_other_module() acquires 0x42::test::Y {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
15 │ let addr = @0x1;
16 │ assert!((&0x42::test::Y<0x42::test::X<bool>>[addr]).field.value == true, 1);
│ ------------------------------------------- called here

error: Invalid operation: access of the field `field` on type `test::Y` can only be done within the defining module `0x42::test`
┌─ tests/file-format-generator/index_acquires_err.move:14:9
14 │ fun test_resource_other_module() acquires 0x42::test::Y {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
15 │ let addr = @0x1;
16 │ assert!((&0x42::test::Y<0x42::test::X<bool>>[addr]).field.value == true, 1);
│ ------------------------------------------------- accessed here

error: Invalid operation: access of the field `value` on type `test::X` can only be done within the defining module `0x42::test`
┌─ tests/file-format-generator/index_acquires_err.move:14:9
14 │ fun test_resource_other_module() acquires 0x42::test::Y {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
15 │ let addr = @0x1;
16 │ assert!((&0x42::test::Y<0x42::test::X<bool>>[addr]).field.value == true, 1);
│ ------------------------------------------------------- accessed here
Original file line number Diff line number Diff line change
@@ -1 +1 @@
processed 14 tasks
processed 21 tasks
Loading

0 comments on commit 7ad3d51

Please sign in to comment.