@@ -1223,87 +1223,33 @@ class P1 { }
1223
1223
);
1224
1224
}
1225
1225
1226
- [Fact ]
1226
+ [Theory, CombinatorialData ]
1227
1227
[WorkItem(48115, "https://github.com/dotnet/roslyn/issues/48115")]
1228
1228
[WorkItem("https://github.com/dotnet/roslyn/issues/66312")]
1229
- public void RestrictedTypesAndPointerTypes()
1230
- {
1231
- var src = @"
1232
- class C<T> { }
1233
- static class C2 { }
1234
- ref struct RefLike{}
1235
-
1236
- unsafe record C(
1237
- int* P1, // 1
1238
- int*[] P2,
1239
- C<int*[]> P3,
1240
- delegate*<int, int> P4, // 2
1241
- void P5, // 3
1242
- C2 P6, // 4, 5
1243
- System.ArgIterator P7, // 6
1244
- System.TypedReference P8, // 7
1245
- RefLike P9, // 8
1246
- delegate*<void>[] P10);
1247
-
1248
- ";
1249
-
1250
- var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, options: TestOptions.UnsafeDebugDll, targetFramework: TargetFramework.Mscorlib461);
1251
- DiagnosticDescription[] expected = [
1252
- // 0.cs(7,5): error CS8908: The type 'int*' may not be used for a field of a record.
1253
- // int* P1, // 1
1254
- Diagnostic(ErrorCode.ERR_BadFieldTypeInRecord, "int*").WithArguments("int*").WithLocation(7, 5),
1255
- // 0.cs(10,5): error CS8908: The type 'delegate*<int, int>' may not be used for a field of a record.
1256
- // delegate*<int, int> P4, // 2
1257
- Diagnostic(ErrorCode.ERR_BadFieldTypeInRecord, "delegate*<int, int>").WithArguments("delegate*<int, int>").WithLocation(10, 5),
1258
- // 0.cs(11,5): error CS1536: Invalid parameter type 'void'
1259
- // void P5, // 3
1260
- Diagnostic(ErrorCode.ERR_NoVoidParameter, "void").WithLocation(11, 5),
1261
- // 0.cs(12,5): error CS0721: 'C2': static types cannot be used as parameters
1262
- // C2 P6, // 4, 5
1263
- Diagnostic(ErrorCode.ERR_ParameterIsStaticClass, "C2").WithArguments("C2").WithLocation(12, 5),
1264
- // 0.cs(12,5): error CS0722: 'C2': static types cannot be used as return types
1265
- // C2 P6, // 4, 5
1266
- Diagnostic(ErrorCode.ERR_ReturnTypeIsStaticClass, "C2").WithArguments("C2").WithLocation(12, 5),
1267
- // 0.cs(13,5): error CS0610: Field or property cannot be of type 'ArgIterator'
1268
- // System.ArgIterator P7, // 6
1269
- Diagnostic(ErrorCode.ERR_FieldCantBeRefAny, "System.ArgIterator").WithArguments("System.ArgIterator").WithLocation(13, 5),
1270
- // 0.cs(14,5): error CS0610: Field or property cannot be of type 'TypedReference'
1271
- // System.TypedReference P8, // 7
1272
- Diagnostic(ErrorCode.ERR_FieldCantBeRefAny, "System.TypedReference").WithArguments("System.TypedReference").WithLocation(14, 5),
1273
- // 0.cs(15,5): error CS8345: Field or auto-implemented property cannot be of type 'RefLike' unless it is an instance member of a ref struct.
1274
- // RefLike P9, // 8
1275
- Diagnostic(ErrorCode.ERR_FieldAutoPropCantBeByRefLike, "RefLike").WithArguments("RefLike").WithLocation(15, 5)];
1276
-
1277
- comp.VerifyDiagnostics(expected);
1278
- comp.VerifyEmitDiagnostics(expected);
1279
- }
1280
-
1281
- [Fact]
1282
- [WorkItem(48115, "https://github.com/dotnet/roslyn/issues/48115")]
1283
- [WorkItem("https://github.com/dotnet/roslyn/issues/66312")]
1284
- public void RestrictedTypesAndPointerTypes_WithEquals()
1285
- {
1286
- var src = @"
1287
- class C<T> { }
1288
- static class C2 { }
1289
- ref struct RefLike{}
1290
-
1291
- unsafe record C(
1292
- int* P1, // 1
1293
- int*[] P2,
1294
- C<int*[]> P3,
1295
- delegate*<int, int> P4, // 2
1296
- void P5, // 3
1297
- C2 P6, // 4, 5
1298
- System.ArgIterator P7, // 6
1299
- System.TypedReference P8, // 7
1300
- RefLike P9, // 8
1301
- delegate*<void>[] P10)
1302
- {
1303
- public virtual bool Equals(C c) => true;
1304
- public override int GetHashCode() => 0;
1305
- }
1306
- ";
1229
+ public void RestrictedTypesAndPointerTypes(bool withEquals)
1230
+ {
1231
+ var src = $$"""
1232
+
1233
+ class C<T> { }
1234
+ static class C2 { }
1235
+ ref struct RefLike{}
1236
+
1237
+ unsafe record C(
1238
+ int* P1, // 1
1239
+ int*[] P2,
1240
+ C<int*[]> P3,
1241
+ delegate*<int, int> P4, // 2
1242
+ void P5, // 3
1243
+ C2 P6, // 4, 5
1244
+ System.ArgIterator P7, // 6
1245
+ System.TypedReference P8, // 7
1246
+ RefLike P9, // 8
1247
+ delegate*<void>[] P10)
1248
+ {
1249
+ {{(withEquals ? "public virtual bool Equals(C c) => true;" : "")}}
1250
+ {{(withEquals ? "public override int GetHashCode() => 0;" : "")}}
1251
+ }
1252
+ """;
1307
1253
1308
1254
var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, options: TestOptions.UnsafeDebugDll, targetFramework: TargetFramework.Mscorlib461);
1309
1255
DiagnosticDescription[] expected = [
@@ -1401,6 +1347,7 @@ public ref struct RefLike{}
1401
1347
public unsafe record C
1402
1348
{
1403
1349
public int* f1 { get; set; } // 1
1350
+ public int* f1_a { get => field; set; } // 1
1404
1351
public int*[] f2 { get; set; }
1405
1352
public C<int*[]> f3 { get; set; }
1406
1353
public delegate*<int, int> f4 { get; set; } // 2
@@ -1418,24 +1365,27 @@ public unsafe record C
1418
1365
// 0.cs(8,12): error CS8908: The type 'int*' may not be used for a field of a record.
1419
1366
// public int* f1 { get; set; } // 1
1420
1367
Diagnostic(ErrorCode.ERR_BadFieldTypeInRecord, "int*").WithArguments("int*").WithLocation(8, 12),
1421
- // 0.cs(11,12): error CS8908: The type 'delegate*<int, int>' may not be used for a field of a record.
1368
+ // 0.cs(9,12): error CS8908: The type 'int*' may not be used for a field of a record.
1369
+ // public int* f1_a { get => field; set; } // 1
1370
+ Diagnostic(ErrorCode.ERR_BadFieldTypeInRecord, "int*").WithArguments("int*").WithLocation(9, 12),
1371
+ // 0.cs(12,12): error CS8908: The type 'delegate*<int, int>' may not be used for a field of a record.
1422
1372
// public delegate*<int, int> f4 { get; set; } // 2
1423
- Diagnostic(ErrorCode.ERR_BadFieldTypeInRecord, "delegate*<int, int>").WithArguments("delegate*<int, int>").WithLocation(11 , 12),
1424
- // 0.cs(12 ,17): error CS0547: 'C.f5': property or indexer cannot have void type
1373
+ Diagnostic(ErrorCode.ERR_BadFieldTypeInRecord, "delegate*<int, int>").WithArguments("delegate*<int, int>").WithLocation(12 , 12),
1374
+ // 0.cs(13 ,17): error CS0547: 'C.f5': property or indexer cannot have void type
1425
1375
// public void f5 { get; set; } // 3
1426
- Diagnostic(ErrorCode.ERR_PropertyCantHaveVoidType, "f5").WithArguments("C.f5").WithLocation(12 , 17),
1427
- // 0.cs(13 ,12): error CS0722: 'C2': static types cannot be used as return types
1376
+ Diagnostic(ErrorCode.ERR_PropertyCantHaveVoidType, "f5").WithArguments("C.f5").WithLocation(13 , 17),
1377
+ // 0.cs(14 ,12): error CS0722: 'C2': static types cannot be used as return types
1428
1378
// public C2 f6 { get; set; } // 4, 5
1429
- Diagnostic(ErrorCode.ERR_ReturnTypeIsStaticClass, "C2").WithArguments("C2").WithLocation(13 , 12),
1430
- // 0.cs(14 ,12): error CS0610: Field or property cannot be of type 'ArgIterator'
1379
+ Diagnostic(ErrorCode.ERR_ReturnTypeIsStaticClass, "C2").WithArguments("C2").WithLocation(14 , 12),
1380
+ // 0.cs(15 ,12): error CS0610: Field or property cannot be of type 'ArgIterator'
1431
1381
// public System.ArgIterator f7 { get; set; } // 6
1432
- Diagnostic(ErrorCode.ERR_FieldCantBeRefAny, "System.ArgIterator").WithArguments("System.ArgIterator").WithLocation(14 , 12),
1433
- // 0.cs(15 ,12): error CS0610: Field or property cannot be of type 'TypedReference'
1382
+ Diagnostic(ErrorCode.ERR_FieldCantBeRefAny, "System.ArgIterator").WithArguments("System.ArgIterator").WithLocation(15 , 12),
1383
+ // 0.cs(16 ,12): error CS0610: Field or property cannot be of type 'TypedReference'
1434
1384
// public System.TypedReference f8 { get; set; } // 7
1435
- Diagnostic(ErrorCode.ERR_FieldCantBeRefAny, "System.TypedReference").WithArguments("System.TypedReference").WithLocation(15 , 12),
1436
- // 0.cs(16 ,12): error CS8345: Field or auto-implemented property cannot be of type 'RefLike' unless it is an instance member of a ref struct.
1385
+ Diagnostic(ErrorCode.ERR_FieldCantBeRefAny, "System.TypedReference").WithArguments("System.TypedReference").WithLocation(16 , 12),
1386
+ // 0.cs(17 ,12): error CS8345: Field or auto-implemented property cannot be of type 'RefLike' unless it is an instance member of a ref struct.
1437
1387
// public RefLike f9 { get; set; } // 8
1438
- Diagnostic(ErrorCode.ERR_FieldAutoPropCantBeByRefLike, "RefLike").WithArguments("RefLike").WithLocation(16 , 12)];
1388
+ Diagnostic(ErrorCode.ERR_FieldAutoPropCantBeByRefLike, "RefLike").WithArguments("RefLike").WithLocation(17 , 12)];
1439
1389
1440
1390
comp.VerifyDiagnostics(expected);
1441
1391
comp.VerifyEmitDiagnostics(expected);
0 commit comments