Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions proposals/low-level-struct-improvements.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,14 @@ For a `new` expression with initializers, the initializer expressions count as a

## Changes in unsafe context

Pointer types are extended to allow managed types as referent type, but only in casts.
Pointer types ([section 22.3](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#223-pointer-types)) are extended to allow managed types as referent type.
Such pointer types are written as a managed type followed by a `*` token. They produce a warning.
The address-of operator is relaxed to accept a variable with a managed type as its operand.

The address-of operator ([section 22.6.5](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#2265-the-address-of-operator)) is relaxed to accept a variable with a managed type as its operand.

The `fixed` statement ([section 22.7](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#227-the-fixed-statement)) is relaxed to accept _fixed_pointer_initializer_ that is the address of a variable of managed type `T` or that is an expression of an _array_type_ with elements of a managed type `T`.

The stack allocation initializer ([section 22.9](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#229-stack-allocation)) is similarly relaxed.

## Considerations
There are considerations other parts of the development stack should consider when evaluating this feature.
Expand Down Expand Up @@ -1648,4 +1653,4 @@ The set of returnable input to the method are:

Given that there is at least one input with a smaller *escape scope* (`ref y` argument) than one of the outputs (`x` argument) the method call is illegal.

This is the logic that the method arguments must match rule is trying to encompass. It goes further as it considers both `scoped` as a way to remove inputs from consideration and `readonly` as a way to remove `ref` as an output (can't assign into a `readonly ref` so it can't be a source of output). These special cases do add complexity to the rules but it's done so for the benefit of the developer. The compiler seeks to remove all inputs and outputs it knows can't contribute to the result to give developers maximum flexibility when calling a member. Much like overload resolution it's worth the effort to make our rules more complex when it creates more flexibility for consumers.
This is the logic that the method arguments must match rule is trying to encompass. It goes further as it considers both `scoped` as a way to remove inputs from consideration and `readonly` as a way to remove `ref` as an output (can't assign into a `readonly ref` so it can't be a source of output). These special cases do add complexity to the rules but it's done so for the benefit of the developer. The compiler seeks to remove all inputs and outputs it knows can't contribute to the result to give developers maximum flexibility when calling a member. Much like overload resolution it's worth the effort to make our rules more complex when it creates more flexibility for consumers.