Skip to content

Commit 3a7a6d5

Browse files
committed
Fix and add test
1 parent 190bc70 commit 3a7a6d5

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEquals.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState,
136136
fields.Add(f);
137137

138138
var parameterType = f.Type;
139-
if (parameterType.ContainsPointerOrFunctionPointer() || parameterType.IsRestrictedType())
139+
if (parameterType.IsPointerOrFunctionPointer() || parameterType.IsRestrictedType())
140140
{
141141
// We'll have reported a diagnostic elsewhere (SourceMemberFieldSymbol.TypeChecks)
142142
foundBadField = true;

src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs

+52
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,58 @@ public unsafe static void Main()
14901490
CompileAndVerify(comp, expectedOutput: "P1 P2 P3 RAN", verify: Verification.Skipped /* pointers */);
14911491
}
14921492

1493+
[Fact]
1494+
[WorkItem(48115, "https://github.com/dotnet/roslyn/issues/48115")]
1495+
[WorkItem("https://github.com/dotnet/roslyn/issues/66312")]
1496+
public void RestrictedTypesAndPointerTypes_PointerTypeAllowedForNestedTypes()
1497+
{
1498+
var src = @"
1499+
class C<T> { }
1500+
1501+
unsafe record C(int*[] P1)
1502+
{
1503+
public unsafe static void Main()
1504+
{
1505+
var x = new C((int*[])null);
1506+
var x2 = x.P1;
1507+
System.Console.Write(""RAN"");
1508+
}
1509+
}
1510+
";
1511+
var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, options: TestOptions.UnsafeDebugExe);
1512+
comp.VerifyEmitDiagnostics();
1513+
var verifier = CompileAndVerify(comp, expectedOutput: "RAN", verify: Verification.Skipped /* pointers */);
1514+
1515+
verifier.VerifyIL("C.Equals(C)", """
1516+
{
1517+
// Code size 55 (0x37)
1518+
.maxstack 3
1519+
IL_0000: ldarg.0
1520+
IL_0001: ldarg.1
1521+
IL_0002: beq.s IL_0035
1522+
IL_0004: ldarg.1
1523+
IL_0005: brfalse.s IL_0032
1524+
IL_0007: ldarg.0
1525+
IL_0008: callvirt "System.Type C.EqualityContract.get"
1526+
IL_000d: ldarg.1
1527+
IL_000e: callvirt "System.Type C.EqualityContract.get"
1528+
IL_0013: call "bool System.Type.op_Equality(System.Type, System.Type)"
1529+
IL_0018: brfalse.s IL_0032
1530+
IL_001a: call "System.Collections.Generic.EqualityComparer<int*[]> System.Collections.Generic.EqualityComparer<int*[]>.Default.get"
1531+
IL_001f: ldarg.0
1532+
IL_0020: ldfld "int*[] C.<P1>k__BackingField"
1533+
IL_0025: ldarg.1
1534+
IL_0026: ldfld "int*[] C.<P1>k__BackingField"
1535+
IL_002b: callvirt "bool System.Collections.Generic.EqualityComparer<int*[]>.Equals(int*[], int*[])"
1536+
IL_0030: br.s IL_0033
1537+
IL_0032: ldc.i4.0
1538+
IL_0033: br.s IL_0036
1539+
IL_0035: ldc.i4.1
1540+
IL_0036: ret
1541+
}
1542+
""");
1543+
}
1544+
14931545
[Fact]
14941546
[WorkItem(48115, "https://github.com/dotnet/roslyn/issues/48115")]
14951547
[WorkItem("https://github.com/dotnet/roslyn/issues/66312")]

0 commit comments

Comments
 (0)