-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a native integer decoding bug #43885
Changes from 1 commit
45e0477
7d8f794
34de2a0
53df7ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ private TypeSymbol TransformType(TypeSymbol type) | |
return TransformPointerType((PointerTypeSymbol)type); | ||
case TypeKind.TypeParameter: | ||
case TypeKind.Dynamic: | ||
IgnoreIndex(); | ||
return type; | ||
case TypeKind.Class: | ||
case TypeKind.Struct: | ||
|
@@ -84,6 +85,8 @@ private NamedTypeSymbol TransformNamedType(NamedTypeSymbol type) | |
return _transformFlags[index] ? TransformTypeDefinition(type) : type; | ||
} | ||
|
||
Debug.Assert(!_transformFlags[index]); | ||
|
||
var allTypeArguments = ArrayBuilder<TypeWithAnnotations>.GetInstance(); | ||
type.GetAllTypeArgumentsNoUseSiteDiagnostics(allTypeArguments); | ||
|
||
|
@@ -106,13 +109,13 @@ private NamedTypeSymbol TransformNamedType(NamedTypeSymbol type) | |
|
||
private ArrayTypeSymbol TransformArrayType(ArrayTypeSymbol type) | ||
{ | ||
Increment(); | ||
IgnoreIndex(); | ||
return type.WithElementType(TransformTypeWithAnnotations(type.ElementTypeWithAnnotations)); | ||
} | ||
|
||
private PointerTypeSymbol TransformPointerType(PointerTypeSymbol type) | ||
{ | ||
Increment(); | ||
IgnoreIndex(); | ||
return type.WithPointedAtType(TransformTypeWithAnnotations(type.PointedAtTypeWithAnnotations)); | ||
} | ||
|
||
|
@@ -125,6 +128,12 @@ private int Increment() | |
throw new ArgumentException(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If we're worried about handwritten attribute data, this could crash the compiler as well. Please add a test. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can't crash the compiler, it's caught above. I already tried to crash it with this :). #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
private void IgnoreIndex() | ||
{ | ||
var index = Increment(); | ||
Debug.Assert(!_transformFlags[index]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This may fail for handwritten attribute data. Please add a test. |
||
} | ||
|
||
private static NamedTypeSymbol TransformTypeDefinition(NamedTypeSymbol type) | ||
{ | ||
switch (type.SpecialType) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -916,6 +916,33 @@ public void AttributeFieldExists() | |
}); | ||
} | ||
|
||
[Theory] | ||
[InlineData("C<dynamic, nint, System.IntPtr>", "C<dynamic, System.IntPtr, System.IntPtr>", "False, False, True, False")] | ||
[InlineData("C<dynamic, nuint, System.UIntPtr>", "C<dynamic, System.UIntPtr, System.UIntPtr>", "False, False, True, False")] | ||
[InlineData("C<T, nint, System.IntPtr>", "C<T, System.IntPtr, System.IntPtr>", "False, False, True, False")] | ||
[InlineData("C<T, nuint, System.UIntPtr>", "C<T, System.UIntPtr, System.UIntPtr>", "False, False, True, False")] | ||
public void NestedNativeIntegerWithPrecedingType(string sourceType, string metadataType, string expectedAttribute) | ||
{ | ||
var comp = CompileAndVerify($@" | ||
class C<T, U, V> | ||
{{ | ||
public {sourceType} F; | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please consider writing out all the cases inline as separate fields in a single test, for readability and to match other tests. |
||
", options: TestOptions.ReleaseDll, parseOptions: TestOptions.RegularPreview, symbolValidator: symbolValidator); | ||
|
||
void symbolValidator(ModuleSymbol module) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Consider making |
||
{ | ||
var expectedAttributes = $@" | ||
C<T, U, V> | ||
[NativeInteger({{ {expectedAttribute} }})] {metadataType} F"; | ||
|
||
AssertNativeIntegerAttributes(module, expectedAttributes); | ||
var c = module.GlobalNamespace.GetTypeMember("C"); | ||
var field = c.GetField("F"); | ||
Assert.Equal(sourceType, field.Type.ToTestDisplayString()); | ||
} | ||
} | ||
|
||
private static TypeDefinition GetTypeDefinitionByName(MetadataReader reader, string name) | ||
{ | ||
return reader.GetTypeDefinition(reader.TypeDefinitions.Single(h => reader.StringComparer.Equals(reader.GetTypeDefinition(h).Name, name))); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is the bug fix.