Skip to content

Commit

Permalink
Code style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TonEnfer committed Dec 9, 2024
1 parent 2016b07 commit 4610d61
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions src/Riok.Mapperly/Descriptors/SymbolAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,42 +392,37 @@ bool IsValidParameter(int i)
{
if (method.Parameters[i] is not { IsParams: true } isParamsParameter)
{
if (!CanAssign(argTypes[i], method.Parameters[i].Type))
{
return false;
}
return CanAssign(argTypes[i], method.Parameters[i].Type);
}
else
{
// see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#params-modifier

var argsToEnd = argTypes.AsSpan(i);
// see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#params-modifier

// for empty args aka Call(params X[]) as Call()
if (argsToEnd.IsEmpty)
{
return true;
}
var argsToEnd = argTypes.AsSpan(i);

var elementType = isParamsParameter.Type.ImplementsGeneric(EnumerableTypeSymbol, out var impl)
// for assignable to IEnumerable<T>
? impl.TypeArguments.First()
// for Span<T> and ReadOnlySpan<T>
: ((INamedTypeSymbol)method.Parameters[i].Type).TypeArguments.First();
// for empty args aka Call(params X[]) as Call()
if (argsToEnd.IsEmpty)
{
return true;
}

//for single arg aka Call(X[]) or Call(X)
if (argsToEnd.Length == 1)
{
return CanAssign(argsToEnd[0], method.Parameters[i].Type) || CanAssign(argsToEnd[0], elementType);
}
var elementType = isParamsParameter.Type.ImplementsGeneric(EnumerableTypeSymbol, out var impl)
// for assignable to IEnumerable<T>
? impl.TypeArguments.First()
// for Span<T> and ReadOnlySpan<T>
: ((INamedTypeSymbol)method.Parameters[i].Type).TypeArguments.First();

// for multiple args
foreach (var typeSymbol in argsToEnd)
//for single arg aka Call(X[]) or Call(X)
if (argsToEnd.Length == 1)
{
return CanAssign(argsToEnd[0], method.Parameters[i].Type) || CanAssign(argsToEnd[0], elementType);
}

// for multiple args
foreach (var typeSymbol in argsToEnd)
{
if (!CanAssign(typeSymbol, elementType))
{
if (!CanAssign(typeSymbol, elementType))
{
return false;
}
return false;
}
}

Expand Down

0 comments on commit 4610d61

Please sign in to comment.