Usage of tick ( ' ) in array assignments -> packed vs unpacked

Hi All,

On some place in the web I’ve found the following example:

int A3[1:3];
int A9[1:9];
A3 = '{1, 2, 3}; ← legal (case0)
A9 = '{3{A3}}; ← illegal (case1)
A9 = {A3, 4, 5, A3, 6}; ← legal (case2)
A9 = '{9{1}}; ← legal (case3)
A9 = {9{1}}; ← illegal (case4)

It’s all about of ’ usage…

Could someone please explane why each case is illegal/legal?

Why case1 is illegal while case2 is legal?

Thank you!

In reply to dmitryl:

assignment patterns require each operands to be assignment compatible with each array element, and there needs to be an operand in the pattern for each element of the array. replication of operands is allowed

Array concatenation requires that each operand be assignment compatible with an element of the array, or an array of elements that are assignment compatible with an element of the array. Replication is not allowed.

case0 is an assignment pattern of 3 operands to an array of three elements

case1 is illegal because Your assignment pattern only has three (repeated) operands where nine are required. And the three operands you do have are not assignment compatible: each element. needs to be an int, not an array of ints.

case2 is an array concatenation whose operands total 9 array elements

case3 is an assignment pattern of 9 replicating operands into an array of 9 elements

case4 is illegal because array concatenation does not allow replication.

See 10.10.1 Unpacked array concatenations compared with array assignment patterns in the 1800-2017 LRM

In reply to dave_59:

While A9 = {A3, 4, 5, A3, 6} is legal, will A9 = '{A3, 4, 5, A3, 6} be illegal?

Will A3 = {1, 2, 3} be illegal?

In reply to dmitryl:

In reply to dave_59:
Whenever a (') is used , the number of operands on the right should be same as the array elements size in the left.
While A9 = {A3, 4, 5, A3, 6} is legal, will A9 = '{A3, 4, 5, A3, 6} be illegal?
→ Yes , it will be illegal as operands on the right are only 5.
Will A3 = {1, 2, 3} be illegal?
→ This is legal. Replication operators do not work in array concatenation.