Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/inline_array'
Browse files Browse the repository at this point in the history
  • Loading branch information
lookbusy1344 committed Nov 20, 2023
2 parents aaab3fe + 358a99d commit eeaf8ba
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions RecordValueAnalyser/NodeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ internal static (ValueEqualityResult, string? membername) ValueEqualityWrapper(I
if (type == null) return (ValueEqualityResult.Ok, null);

if (IsStrictlyInvalid(type)) return (ValueEqualityResult.Failed, null); // object and dynamic

if (HasSimpleEquality(type)) return (ValueEqualityResult.Ok, null); // primitive types, string, enum
if (IsInlineArray(type)) return (ValueEqualityResult.Failed, null); // Inline array structs lack value semantics

if (!type.IsTupleType)
{
// for tuples we ignore Equals(T) and Equals(object)
Expand Down Expand Up @@ -147,7 +148,7 @@ internal static (ITypeSymbol? membertype, string? membername, bool isproperty) G
private static bool IsObjectType(ITypeSymbol? type) => type?.SpecialType == SpecialType.System_Object;

/// <summary>
/// Record class or Record struct. *** CONFIRM THIS BEHAVIOUR
/// Record class or Record struct
/// </summary>
private static bool IsRecordType(ITypeSymbol? type) => type != null && (type.IsRecord || (type.TypeKind == TypeKind.Struct && type.IsReadOnly));

Expand All @@ -156,6 +157,15 @@ internal static (ITypeSymbol? membertype, string? membername, bool isproperty) G
/// </summary>
private static bool IsStruct(ITypeSymbol? type) => type != null && type.TypeKind == TypeKind.Struct;

/// <summary>
/// True if this is an inline array (new in .NET8). These lack value semantics
/// </summary>
private static bool IsInlineArray(ITypeSymbol? type) =>
type != null
&& type.TypeKind == TypeKind.Struct
&& type.GetAttributes().Any(attribute =>
attribute.AttributeClass?.ToDisplayString() == "System.Runtime.CompilerServices.InlineArrayAttribute");

/// <summary>
/// Is this always invalid? (object, dynamic, etc)
/// </summary>
Expand Down

0 comments on commit eeaf8ba

Please sign in to comment.