Right now there's no rule on how restricted types (like ref structs) should behave in async and iterator methods. There are clearly illegal cases: pending restricted types over await and yield is not possible to implement, so it must be illegal.
However, it's unclear how this should behave if restricted types are not pended over a branch. It's possible to allow this behavior, but it becomes an obtuse and delicate balance -- all locals of restricted types are also currently disallowed because it hurts debuggibility, but not all expressions of restricted type are disallowed. While using the result of a restricted method as an expression may be safe, it seems reasonable that a user would assume that they could take the same code and introduce a local variable for the restricted type. This then becomes an error. Moreover, we may be allowing users to veer into very dangerous design territory, as minor refactorings can easily cause the code to pend the expression over an await, producing an error.
It seems the compiler already allows expressions of restricted types in async methods, as long as they don't pend the value over an await. We should decide if we like this behavior, or if we should treat this as a bug and produce a breaking change for code of this form.
Right now there's no rule on how restricted types (like ref structs) should behave in async and iterator methods. There are clearly illegal cases: pending restricted types over
await
andyield
is not possible to implement, so it must be illegal.However, it's unclear how this should behave if restricted types are not pended over a branch. It's possible to allow this behavior, but it becomes an obtuse and delicate balance -- all locals of restricted types are also currently disallowed because it hurts debuggibility, but not all expressions of restricted type are disallowed. While using the result of a restricted method as an expression may be safe, it seems reasonable that a user would assume that they could take the same code and introduce a local variable for the restricted type. This then becomes an error. Moreover, we may be allowing users to veer into very dangerous design territory, as minor refactorings can easily cause the code to pend the expression over an
await
, producing an error.It seems the compiler already allows expressions of restricted types in async methods, as long as they don't pend the value over an
await
. We should decide if we like this behavior, or if we should treat this as a bug and produce a breaking change for code of this form.