Skip to content

feat(sv): shallow copies of class-valued expressions, in any context and of null #1891

Open

Description

@tignear

Problem

Shallow copies (new h, IEEE 1800-2023 8.12; #1810) are lowered only when the whole right-hand side of a handle assignment, declaration initializer or property initializer is new <operand>, and only when the operand is a handle variable, an element of an array of handles or a property. These valid forms are rejected:

Form Example Result
Operand that is a class-valued call, cast or conditional C dst = new make_c(); "shallow copy of a value that is not a class handle"
Copy outside an assignment, where the context supplies the class take(new h);, return new h;, x = c ? new a : b; unsupported primary expression
null operand dst = new null; parse error, instead of the null-copy runtime error

Expected

Infer the operand's class from its expression type, lower ExprKind::Copy wherever a class-valued expression is bound (arguments, return values, conditional branches), and parse new null as a copy whose class comes from the destination, faulting at run time like other null copies.

Found in review of #1810.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions