You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wasn't entirely sure if this was worth reporting, as the issue can be avoided by simply returning early when typeof(T).IsGenericParam is true. However, it took me some time (and moments of confusion) to figure this out, so I figured I should report it anyway.
The issue manifests in two ways:
Attempting to assign through the valuePtr pointer results in the error:
Cannot assign to read-only local variable 'valuePtr'
Trying to read valuePtr from the else branch results in the error:
Identifier not found
using System;
using System.Collections;
using System.Reflection;
using System.Diagnostics;
namespace simple_test;
namespace TypeTraits
{
static
{
struct Yes;
struct No;
struct IsIndexable<T, TKey>
{
public typealias Result = comptype(_isIndexable(typeof(T), typeof(TKey)));
private class IndexerProperty
{
}
[Comptime]
private static Type _isIndexable(Type type, Type keyType)
{
Dictionary<StringView, IndexerProperty> indexers = scope .();
if (indexers.TryAdd("foo", let keyPtr, let valuePtr))
{
*valuePtr = null; // Cannot assign to read-only local variable 'valuePtr'
}
else
{
IndexerProperty indexerProp = (.)*valuePtr; // Identifier not found
Debug.WriteLine(indexerProp.ToString(.. scope .()));
}
return typeof(No);
}
}
}
}
The comptime will still crash with a null pointer at (.)*valuePtr if you don't have the IsGenericParam test, but at least the comptime method will actually generate without error now.
I wasn't entirely sure if this was worth reporting, as the issue can be avoided by simply returning early when
typeof(T).IsGenericParam
is true. However, it took me some time (and moments of confusion) to figure this out, so I figured I should report it anyway.The issue manifests in two ways:
valuePtr
pointer results in the error:valuePtr
from theelse
branch results in the error:Tested with: 05cda98
The text was updated successfully, but these errors were encountered: