Minor PR feedback:

* Clarify tests.
* Remove a redundant condition.
上级 687083d6
......@@ -3334,7 +3334,7 @@ static CustomModifier getCustomModifierForType(INamedTypeSymbol type, CSharpComp
}
var internalType = type.EnsureCSharpSymbolOrNull($"{nameof(callingConventionTypes)}[{index}]");
if (!FunctionPointerTypeSymbol.IsCallingConventionModifier(internalType) || @this.Assembly.CorLibrary != internalType.ContainingAssembly.CorLibrary)
if (!FunctionPointerTypeSymbol.IsCallingConventionModifier(internalType) || @this.Assembly.CorLibrary != internalType.ContainingAssembly)
{
throw new ArgumentException(string.Format(CSharpResources.CallingConventionTypeIsInvalid, type.ToDisplayString()));
}
......
......@@ -1655,6 +1655,10 @@ public void PublicApi_CallingConventions_Modopts()
AssertEx.Equal("delegate* unmanaged[Cdecl, Stdcall]<System.String modopt(System.Runtime.CompilerServices.CallConvCdecl) modopt(System.Runtime.CompilerServices.CallConvStdcall)>", ptr.ToTestDisplayString());
ptr = comp.CreateFunctionPointerTypeSymbol(@string, returnRefKind: RefKind.RefReadOnly, parameterTypes: ImmutableArray<ITypeSymbol>.Empty, parameterRefKinds: ImmutableArray<RefKind>.Empty, SignatureCallingConvention.Unmanaged, ImmutableArray.Create(cdeclType, stdcallType)!);
AssertEx.Equal("delegate* unmanaged[Cdecl, Stdcall]<ref readonly modopt(System.Runtime.CompilerServices.CallConvCdecl) modopt(System.Runtime.CompilerServices.CallConvStdcall) modreq(System.Runtime.InteropServices.InAttribute) System.String>", ptr.ToTestDisplayString());
ptr = comp.CreateFunctionPointerTypeSymbol(@string, returnRefKind: RefKind.None, parameterTypes: ImmutableArray<ITypeSymbol>.Empty, parameterRefKinds: ImmutableArray<RefKind>.Empty, SignatureCallingConvention.Unmanaged, ImmutableArray.Create(cdeclType)!);
AssertEx.Equal("delegate* unmanaged[Cdecl]<System.String modopt(System.Runtime.CompilerServices.CallConvCdecl)>", ptr.ToTestDisplayString());
Assert.Equal(SignatureCallingConvention.Unmanaged, ptr.Signature.CallingConvention);
}
[Fact]
......@@ -1959,11 +1963,11 @@ public static class RuntimeFeature
}
", options: TestOptions.UnsafeReleaseDll, parseOptions: TestOptions.RegularPreview);
var mainComp = CreateCompilation("", references: new[] { otherCorLib.ToMetadataReference() });
var mainComp = CreateCompilation("");
var returnType = mainComp.GetSpecialType(SpecialType.System_String).GetPublicSymbol();
var testConvention = otherCorLib.GetTypeByMetadataName("System.Runtime.CompilerServices.CallConvTest");
Assert.NotNull(testConvention);
Assert.True((object)testConvention!.ContainingAssembly.CorLibrary != mainComp.Assembly.CorLibrary);
Assert.NotSame(testConvention!.ContainingAssembly.CorLibrary, mainComp.Assembly.CorLibrary);
Assert.True(FunctionPointerTypeSymbol.IsCallingConventionModifier(testConvention));
Assert.Throws<ArgumentException>(() => mainComp.CreateFunctionPointerTypeSymbol(
......
......@@ -140,19 +140,6 @@ public static ImmutableArray<byte> ToImmutable(this MemoryStream stream)
return ImmutableArray.CreateRange(items, map);
}
/// <summary>
/// Maps an immutable array to another immutable array, passing the current index.
/// </summary>
/// <typeparam name="TItem"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="items">The sequence to map</param>
/// <param name="map">The mapping delegate</param>
/// <returns>If the items's length is 0, this will return an empty immutable array.</returns>
public static ImmutableArray<TResult> SelectAsArray<TItem, TResult>(this ImmutableArray<TItem> items, Func<TItem, int, TResult> map)
{
return items.SelectAsArray((item, i, mapper) => mapper(item, i), map);
}
/// <summary>
/// Maps an immutable array to another immutable array.
/// </summary>
......
......@@ -76,7 +76,7 @@ public enum SymbolDisplayMiscellaneousOptions
IncludeNotNullableReferenceTypeModifier = 1 << 8,
/// <summary>
/// Explicitly put `managed` as the calling convention for function pointer types.
/// Use the `managed` keyword for managed function pointer types.
/// </summary>
UseExplicitManagedCallingConventionSpecifier = 1 << 9,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册