Skip to content

Test plan for "ref and unsafe in iterators and async" feature #72662

@jjonescz

Description

@jjonescz

Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-13.0/ref-unsafe-in-iterators-async.md
Feature branch: https://github.com/dotnet/roslyn/tree/features/RefInAsync
Label: https://github.com/dotnet/roslyn/labels/New%20Feature%20-%20Ref%2FUnsafe%20in%20Iterators%2FAsync

  • Review feature specification at LDM
  • Breaking change around unsafe context within iterators is documented
  • language version
    • ref / ref struct local in
      • async method
      • iterator method
    • unsafe block is allowed in C# 13 in
      • async method (this is a preserved legacy behavior)
      • iterator method
    • unsafe modifier is allowed on an iterator in C# 13, still an error (a language version error) in previous versions
      • regular method
      • property get
      • local function
      • operator
    • effect on unsafe context within iterator's body (the breaking change)
      • regular method
      • property get
      • local function
      • operator
  • use ref / ref struct local
    • within / across await
    • within / across yield return; in
      • regular iterators
      • async iterators
    • across yield break; in
      • regular iterators
      • async iterators
    • within / across async foreach block
    • yield in nested block
    • within async lambda / local function
    • within iterator local function
    • within property / indexer get iterator
    • error in async / iterator even in unsafe context
    • await in elements of stackalloc, the result span should be usable afterwards
    • async Task<int[]> M() => ... ReadOnlySpan<int> x = await M(); is expected to work
    • Buffer2<int> b = [await a, await b]; // inline array type (ref struct)
    • using (refStruct = ...) { await ...; }
    • foreach (var _ in refStruct) { await ...; }
    • Interpolation handlers with awaits in the middle handler is a ref struct
      • no awaits in async method should work
      • Has await should be blocked (turns out it works but doesn't use the interpolation handler)
  • unsafe context
    • unannotated / unsafe containing type
    • unannotated / unsafe iterator method declaration
    • unannotated / unsafe iterator block
    • unannotated / unsafe local function
    • unannotated lambda
    • unannotated / unsafe property
    • unannotated / unsafe property / indexer get iterator
  • within unsafe context
    • error for await (confirm we have a legacy test)
    • error for yield return;
    • no diagnostic for yield break;
  • within lock
    • next warning waive warning for yield return; for legacy lock
    • error for yield return; for Lock type
    • no diagnostic for yield break;
  • taking address of local / parameter
    • error in iterator method
    • error in iterator method for an indirect case
    • warning in async method (C#12 warning wave)
  • taking address of a field is allowed in async/iterator

Related:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions