How to resolve counterintuitive CS9091 #124460
-
|
I'm currently having trouble resolving warning CS9091. public readonly partial struct UniBigInt
{
private readonly v256[]? m_Value;
private readonly int m_Sign;
public static unsafe NativeResource operator +(in UniBigInt a, in UniBigInt b)
{
NativeResource result;
fixed (v256* aPtr = a.m_Value, bPtr = b.m_Value)
{
var aSpan = new ReadOnlyBurstSpan<v256>(aPtr, a.m_Value?.Length ?? 0);
var bSpan = new ReadOnlyBurstSpan<v256>(bPtr, b.m_Value?.Length ?? 0);
// Here, aSpan and bSpan issue CS9091
// "This returns local by reference but it is not a ref local"
Add(aSpan, a.m_Sign, bSpan, b.m_Sign, out result);
}
return result;
}
// The BurstCompile specification does not allow you to change the signature.
// [BurstCompile]
static void Add(in ReadOnlyBurstSpan<v256> aValue, int aSign, in ReadOnlyBurstSpan<v256> bValue, int bSign, out NativeResource result)
{
// Do Something (omitted)
result = default;
}
}
internal unsafe readonly struct ReadOnlyBurstSpan<T> where T : unmanaged
{
private readonly T* m_Ptr;
private readonly int m_Length;
public ReadOnlyBurstSpan(T* ptr, int length)
{
m_Ptr = ptr;
m_Length = length;
}
}
public readonly ref struct NativeResource
{
// omitted
}
public struct v256
{
// omitted (defined in unity)
}
|
Beta Was this translation helpful? Give feedback.
Answered by
huoyaoyuan
Feb 16, 2026
Replies: 1 comment 1 reply
-
|
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
andanteyk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
out NativeResource resultis treated as return value, and sinceNativeResourceis aref struct, it's applicable to lifetime tracking.in ReadOnlyBurstSpan<v256> aValueshould bescopedto indicate that its won't be re-assigned to other variables.