From 977cd0d8df756f7dfb60221c9b9647ed716d2aee Mon Sep 17 00:00:00 2001 From: Louis Brunner Date: Mon, 20 Mar 2023 16:35:45 +0000 Subject: [PATCH] cgen: better alias handling for references/shared (#17656) --- vlib/v/tests/aliased_field_access_test.v | 12 ++++++++++++ .../known_errors/testdata/shared_in_alias_test.vv | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 vlib/v/tests/aliased_field_access_test.v create mode 100644 vlib/v/tests/known_errors/testdata/shared_in_alias_test.vv diff --git a/vlib/v/tests/aliased_field_access_test.v b/vlib/v/tests/aliased_field_access_test.v new file mode 100644 index 0000000000..94364ccea7 --- /dev/null +++ b/vlib/v/tests/aliased_field_access_test.v @@ -0,0 +1,12 @@ +struct Data { + field int +} + +type AliasWithPtr = &Data + +fn test_aliased_field_access_test() { + data_with_ptr := AliasWithPtr(&Data{ + field: 1 + }) + assert data_with_ptr.field == 1 +} diff --git a/vlib/v/tests/known_errors/testdata/shared_in_alias_test.vv b/vlib/v/tests/known_errors/testdata/shared_in_alias_test.vv new file mode 100644 index 0000000000..eecb6e496d --- /dev/null +++ b/vlib/v/tests/known_errors/testdata/shared_in_alias_test.vv @@ -0,0 +1,12 @@ +struct Data { + field int +} + +type AliasWithShared = shared Data + +fn test_shared_in_alias() { + data_with_shared := AliasWithShared(&Data{ + field: 1 + }) + assert data_with_shared.field == 1 +}