[x] Verify evaluation order, and side-effects on structs (didn't copy) (CustomFixedStructSideeffects, CustomFixedClassSideeffects, CustomFixedGenericSideeffects)
[ ] Conversions are not considered
[ ] fixed (int* ptr = await e) ... (unsafe and async don't work together)
[ ] Scenarios with struct, using this struct fixed (int* ptr = this) // in a struct or readonly struct (should copy, depending on instance or extension method)
Specification
csharplang
Tests
GetPinnableReference
method (blocking)SimpleCaseOfCustomFixed
CustomFixedStructVariousErr07_Optional
GetPinnableReference
marked asObsolete
CustomFixedStructVariousErr05_Obsolete`GetPinnableReference
with use-site errorCustomFixedStructVariousErr06_UseSite
GetPinnableReference
(CustomFixedStructVariousErr01)GetPinnableReference<T>()
(ignored)CustomFixedStructVariousErr04
GetPinnableReference<T>()
(instance) and GetPinnableReference() (extension), the extension is pickedSimpleCaseOfCustomFixedExt
FixStringArrayExtensionHelpersIgnored
FixStringMissingAllHelpers
FixedHelpersOnStringAndArray
[x] GPR on System.Object (ignored on String/Array, used on others)
FixedHelperOnObject
fixed (int* ptr = nullableArray) // with GetPinnableExtension on NullableArray
(ok) (CustomFixedStructNullable)fixed (int* ptr = nullableArray)
(error because operator doesn't lift) (CustomFixedStructNullableErr)unmanaged
constraint:void M<T>(ImmutableArray<T> tArray) where T : unmanaged { fixed(T* x = tArray) ... }
(ok)fixed
, notify F#GetPinnableReference
should produce ambiguity (CustomFixedErrAmbiguous)GetPinnableReference
that returns anullptr
(SimpleCaseOfCustomFixedNull)fixed (int* ptr = immutableArray) { ... /* write to the array */ ... }
even thoughref readonly int GetPinnableRefererence()
fixed (int* ptr = (C)null)
// get a nullptr (SimpleCaseOfCustomFixedNull)fixed (int* ptr = someStruct)
(avoid copying the struct) (SimpleCaseOfCustomFixedStruct)fixed (int* ptr = someClass)
(must copy the reference)fixed (int* ptr = tWithPinnable)
(ok, check for struct, then don't copy, but if ref type, then do copy) (SimpleCaseOfCustomFixedGeneric)GetPinnableReference
is not exposed in semantic model or IOperationfixed (int* ptr = (dynamic)immutableArray)
(fails, no dynamic dispatch) (CustomFixedErrDynamic)fixed (int* ptr = await e) ...
(unsafe and async don't work together)this
structfixed (int* ptr = this) // in a struct or readonly struct (should copy, depending on instance or extension method)
IDE
GetPinnableReference
should the usage infixed
(requires some semantic model changes) (filed https://github.com/dotnet/roslyn/issues/25610)Spec
Language proposal https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/pattern-based-fixed.md PR https://github.com/dotnet/roslyn/pull/24469