Skip to content

Commit

Permalink
Fix some issues around arrays and nested generics that running the an…
Browse files Browse the repository at this point in the history
…alyzer against CoreLib discovered
  • Loading branch information
jkoritzinsky committed Jul 21, 2022
1 parent d9f0931 commit a031bd4
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 30 deletions.
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
is_global = true

# AD0001: Analyzer threw an exception
dotnet_diagnostic.AD0001.severity = error
dotnet_diagnostic.AD0001.severity = suggestion

# BCL0001: Ensure minimum API surface is respected
dotnet_diagnostic.BCL0001.severity = warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public void AnalyzeAttribute(SyntaxNodeAnalysisContext context)
DiagnosticReporter managedTypeReporter = DiagnosticReporter.CreateForLocation(syntax.FindArgumentWithNameOrArity("managedType", 0).FindTypeExpressionOrNullLocation(), context.ReportDiagnostic);
INamedTypeSymbol entryType = (INamedTypeSymbol)attributedSymbol;

INamedTypeSymbol? managedTypeInAttribute = (INamedTypeSymbol?)attr.ConstructorArguments[0].Value;
ITypeSymbol? managedTypeInAttribute = (ITypeSymbol?)attr.ConstructorArguments[0].Value;
if (managedTypeInAttribute is null)
{
managedTypeReporter.CreateAndReportDiagnostic(ManagedTypeMustBeNonNullRule, entryType.ToDisplayString());
Expand All @@ -502,7 +502,7 @@ public void AnalyzeAttribute(SyntaxNodeAnalysisContext context)

if (!ManualTypeMarshallingHelper.TryResolveManagedType(
entryType,
managedTypeInAttribute,
ManualTypeMarshallingHelper.ReplaceGenericPlaceholderInType(managedTypeInAttribute, entryType, context.Compilation),
ManualTypeMarshallingHelper.IsLinearCollectionEntryPoint(entryType),
(entryType, managedType) => managedTypeReporter.CreateAndReportDiagnostic(ManagedTypeMustBeClosedOrMatchArityRule, managedType, entryType), out ITypeSymbol managedType))
{
Expand Down Expand Up @@ -753,7 +753,8 @@ void ReportDiagnosticsForMismatchedMemberSignatures(DiagnosticReporter diagnosti
}
}

ITypeSymbol expectedUnmanagedCollectionElementType = marshallerType.TypeArguments[marshallerType.TypeArguments.Length - 1];
var (typeArguments, _) = marshallerType.GetAllTypeArgumentsIncludingInContainingTypes();
ITypeSymbol expectedUnmanagedCollectionElementType = typeArguments[typeArguments.Length - 1];
VerifyUnmanagedCollectionElementType(methods.UnmanagedValuesSource, expectedUnmanagedCollectionElementType, _readOnlySpanOfT);
VerifyUnmanagedCollectionElementType(methods.UnmanagedValuesDestination, expectedUnmanagedCollectionElementType, _spanOfT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,96 @@
<target state="needs-review-translation">Nativní typ {0} pro spravovaný typ {1} musí být uzavřený obecný typ, nebo musí mít stejnou aritu jako spravovaný typ.</target>
<note />
</trans-unit>
<trans-unit id="ReturnTypeMustBeExpectedTypeDescription">
<source>The return type the two method must be the expected type.</source>
<target state="new">The return type the two method must be the expected type.</target>
<note />
</trans-unit>
<trans-unit id="ReturnTypeMustBeExpectedTypeMessage">
<source>The return type of '{0}' must be '{1}'</source>
<target state="new">The return type of '{0}' must be '{1}'</target>
<note />
</trans-unit>
<trans-unit id="ReturnTypesMustMatchDescription">
<source>The return types of the two methods must be the same type.</source>
<target state="new">The return types of the two methods must be the same type.</target>
<note />
</trans-unit>
<trans-unit id="ReturnTypesMustMatchMessage">
<source>The return type of '{0}' must be the same type as the return type of '{1}'</source>
<target state="new">The return type of '{0}' must be the same type as the return type of '{1}'</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionCallerAllocConstructorMustHaveBufferSizeDescription">
<source>When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span&lt;T&gt;' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer.</source>
<target state="new">When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span&lt;T&gt;' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer.</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionCallerAllocConstructorMustHaveBufferSizeMessage">
<source>The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span&lt;{1}&gt;'</source>
<target state="new">The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span&lt;{1}&gt;'</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionInRequiresCollectionMethodsDescription">
<source>A contiguous collection marshaller that supports marshalling from managed to unmanaged must provide a 'GetManagedValuesSource' that takes the managed value as a parameter and returns a 'ReadOnlySpan&lt;&gt;' and a 'GetNativeValuesDestination' method that takes the unmanaged value as a parameter and returns a 'Span&lt;&gt;'</source>
<target state="new">A contiguous collection marshaller that supports marshalling from managed to unmanaged must provide a 'GetManagedValuesSource' that takes the managed value as a parameter and returns a 'ReadOnlySpan&lt;&gt;' and a 'GetNativeValuesDestination' method that takes the unmanaged value as a parameter and returns a 'Span&lt;&gt;'</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionInRequiresCollectionMethodsMessage">
<source>The type '{0}' specifies that it supports the '{1}' marshal mode, but it does not provide a 'GetManagedValuesSource' that takes '{2}' as a parameter and returns a 'ReadOnlySpan&lt;&gt;' and a 'GetNativeValuesDestination' method that takes the unmanaged value as a parameter and returns a 'Span&lt;&gt;'</source>
<target state="new">The type '{0}' specifies that it supports the '{1}' marshal mode, but it does not provide a 'GetManagedValuesSource' that takes '{2}' as a parameter and returns a 'ReadOnlySpan&lt;&gt;' and a 'GetNativeValuesDestination' method that takes the unmanaged value as a parameter and returns a 'Span&lt;&gt;'</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionOutRequiresCollectionMethodsDescription">
<source>A contiguous collection marshaller that supports marshalling from unmanaged to managed must provide a 'GetManagedValuesDestination' that takes the unmanaged value and an 'int' and returns a 'Span&lt;&gt;' and a 'GetNativeValuesSource' method that takes the unmanaged value and an 'int' and returns a 'ReadOnlySpan&lt;&gt;'.</source>
<target state="new">A contiguous collection marshaller that supports marshalling from unmanaged to managed must provide a 'GetManagedValuesDestination' that takes the unmanaged value and an 'int' and returns a 'Span&lt;&gt;' and a 'GetNativeValuesSource' method that takes the unmanaged value and an 'int' and returns a 'ReadOnlySpan&lt;&gt;'.</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionOutRequiresCollectionMethodsMessage">
<source>The type '{0}' specifies that it supports the '{1}' marshal mode, but it does not provide a 'GetManagedValuesDestination' that takes '{2}' and an 'int' and returns a 'Span&lt;&gt;' and a 'GetNativeValuesSource' method that takes the unmanaged value and an 'int' and returns a 'ReadOnlySpan&lt;&gt;'</source>
<target state="new">The type '{0}' specifies that it supports the '{1}' marshal mode, but it does not provide a 'GetManagedValuesDestination' that takes '{2}' and an 'int' and returns a 'Span&lt;&gt;' and a 'GetNativeValuesSource' method that takes the unmanaged value and an 'int' and returns a 'ReadOnlySpan&lt;&gt;'</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsDescription">
<source>A statelss contiguous collection marshaller that supports marshalling from managed to unmanaged must provide an 'AllocateContainerForManagedElements' method taking the unmanaged type as the first parameter and the number of elements as an 'int' parameter</source>
<target state="new">A statelss contiguous collection marshaller that supports marshalling from managed to unmanaged must provide an 'AllocateContainerForManagedElements' method taking the unmanaged type as the first parameter and the number of elements as an 'int' parameter</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsMessage">
<source>The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but does not provide a two-parameter 'AllocateContainerForManagedElements' method that takes the unmanaged type as the first parameter and an 'int' as the second parameter</source>
<target state="new">The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but does not provide a two-parameter 'AllocateContainerForManagedElements' method that takes the unmanaged type as the first parameter and an 'int' as the second parameter</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionRequiresTwoParameterAllocateContainerForUnmanagedElementsDescription">
<source>A statelss contiguous collection marshaller that supports marshalling from managed to unmanaged must provide an 'AllocateContainerForUnmanagedElements' method taking the managed type as the first parameter and providing the number of elements as an 'out int' parameter</source>
<target state="new">A statelss contiguous collection marshaller that supports marshalling from managed to unmanaged must provide an 'AllocateContainerForUnmanagedElements' method taking the managed type as the first parameter and providing the number of elements as an 'out int' parameter</target>
<note />
</trans-unit>
<trans-unit id="StatelessLinearCollectionRequiresTwoParameterAllocateContainerForUnmanagedElementsMessage">
<source>The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but does not provide a two-parameter 'AllocateContainerForUnmanagedElements' method that takes a '{2}' as the first parameter and an 'out int' as the second parameter</source>
<target state="new">The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but does not provide a two-parameter 'AllocateContainerForUnmanagedElements' method that takes a '{2}' as the first parameter and an 'out int' as the second parameter</target>
<note />
</trans-unit>
<trans-unit id="StatelessRequiresConvertToManagedDescription">
<source>A stateless value marshaller that supports marshalling from unmanaged to managed must provide a 'ConvertToManaged' method that takes the unmanaged type as a parameter and returns the the managed type.</source>
<target state="new">A stateless value marshaller that supports marshalling from unmanaged to managed must provide a 'ConvertToManaged' method that takes the unmanaged type as a parameter and returns the the managed type.</target>
<note />
</trans-unit>
<trans-unit id="StatelessRequiresConvertToManagedMessage">
<source>The type '{0}' specifies it supports the '{1}' marshal mode, but it does not provide a 'ConvertToManaged' method that takes the unmanaged type as a parameter and returns '{2}'</source>
<target state="new">The type '{0}' specifies it supports the '{1}' marshal mode, but it does not provide a 'ConvertToManaged' method that takes the unmanaged type as a parameter and returns '{2}'</target>
<note />
</trans-unit>
<trans-unit id="StatelessValueInRequiresConvertToUnmanagedDescription">
<source>A 'Value'-kind native type must provide a one-parameter constructor taking the managed type as a parameter</source>
<target state="new">A 'Value'-kind native type must provide a one-parameter constructor taking the managed type as a parameter</target>
<note />
</trans-unit>
<trans-unit id="StatelessValueInRequiresConvertToUnmanagedMessage">
<source>The type '{0}' specifies that it supports the '{1}' marshal mode of '{2}' but does not provide a one-parameter 'ConvertToUnmanaged' that takes a '{2}' as a parameter and returns a value of an 'unmanaged' type.</source>
<target state="new">The type '{0}' specifies that it supports the '{1}' marshal mode of '{2}' but does not provide a one-parameter 'ConvertToUnmanaged' that takes a '{2}' as a parameter and returns a value of an 'unmanaged' type.</target>
<note />
</trans-unit>
<trans-unit id="ToUnmanagedFromManagedTypesMustMatchDescription">
<source>The return type of 'ConvertToUnmanaged' and the parameter type of 'ConvertToManaged' must be the same.</source>
<target state="new">The return type of 'ConvertToUnmanaged' and the parameter type of 'ConvertToManaged' must be the same.</target>
Expand All @@ -347,9 +437,9 @@
<target state="new">The return type of 'ConvertToUnmanaged' and the parameter type of 'ConvertToManaged' must be the same</target>
<note />
</trans-unit>
<trans-unit id="TypeMustBeUnmanagedOrStrictlyBlittableDescription">
<source>A native type must be blittable.</source>
<target state="translated">Nativní typ musí být přenositelný.</target>
<trans-unit id="TypeMustBeUnmanagedDescription">
<source>An unmanaged type for a marshaller must be unmanaged.</source>
<target state="new">An unmanaged type for a marshaller must be unmanaged.</target>
<note />
</trans-unit>
<trans-unit id="TypeMustBeUnmanagedMessage">
Expand Down
Loading

0 comments on commit a031bd4

Please sign in to comment.