Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfead0aa

Browse files
authored
Enable negative byref tests (#5237)
* Checking negative tests for byrefs* Added byref test baseline
1 parentcfd4612 commitfead0aa

File tree

3 files changed

+94
-62
lines changed

3 files changed

+94
-62
lines changed

‎tests/fsharp/core/byrefs/test.bsl‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
test.fsx(31,34,31,40): typecheck error FS3224: The byref pointer is readonly, so this write isnot permitted.
3+
4+
test.fsx(34,32,34,40): typecheck error FS0257: Invalid mutation of a constant expression. Consider copying the expressionto a mutable local, e.g. 'let mutable x= ...'.
5+
6+
test.fsx(38,36,38,38): typecheck error FS0001: Type mismatch. Expecting a
7+
'byref<'T>'
8+
but given a
9+
'inref<'T>'
10+
The type 'ByRefKinds.InOut' doesnot match the type 'ByRefKinds.In'
11+
12+
test.fsx(42,36,42,38): typecheck error FS0001: Type mismatch. Expecting a
13+
'outref<'T>'
14+
but given a
15+
'inref<'T>'
16+
The type 'ByRefKinds.Out' doesnot match the type 'ByRefKinds.In'
17+
18+
test.fsx(47,38,47,40): typecheck error FS0001: Type mismatch. Expecting a
19+
'byref<'T>'
20+
but given a
21+
'inref<'T>'
22+
The type 'ByRefKinds.InOut' doesnot match the type 'ByRefKinds.In'
23+
24+
test.fsx(52,38,52,40): typecheck error FS0001: Type mismatch. Expecting a
25+
'outref<'T>'
26+
but given a
27+
'inref<'T>'
28+
The type 'ByRefKinds.Out' doesnot match the type 'ByRefKinds.In'
29+
30+
test.fsx(57,38,57,40): typecheck error FS0001: Type mismatch. Expecting a
31+
'byref<'T>'
32+
but given a
33+
'inref<'T>'
34+
The type 'ByRefKinds.InOut' doesnot match the type 'ByRefKinds.In'
35+
36+
test.fsx(62,38,62,40): typecheck error FS0001: Type mismatch. Expecting a
37+
'outref<'T>'
38+
but given a
39+
'inref<'T>'
40+
The type 'ByRefKinds.Out' doesnot match the type 'ByRefKinds.In'
41+
42+
test.fsx(66,34,66,47): typecheck error FS1204: This construct isfor usein the FSharp.Core libraryand shouldnot be used directly
43+
44+
test.fsx(66,34,66,47): typecheck error FS1204: This construct isfor usein the FSharp.Core libraryand shouldnot be used directly

‎tests/fsharp/core/byrefs/test.fsx‎

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,54 @@ let check s actual expected =
1717
if actual= expectedthen printfn"%s: OK" s
1818
else report_failure(sprintf"%s: FAILED, expected%A, got%A" s expected actual)
1919

20-
letcheck2 s expected actual= check s actual expected
20+
letcheck2 s expected actual= check s actual expected
21+
22+
[<Struct>]
23+
typeS=
24+
[<DefaultValue(true)>]
25+
val mutableX:int
26+
27+
#if NEGATIVE
28+
moduleByrefNegativeTests=
29+
30+
moduleWriteToInRef=
31+
letf1(x:inref<int>)= x<-1// not allowed
32+
33+
moduleWriteToInRefStructInner=
34+
letf1(x:inref<S>)= x.X<-1//not allowed
35+
36+
moduleInRefToByRef=
37+
letf1(x:byref<'T>)=1
38+
letf2(x:inref<'T>)= f1&x// not allowed
39+
40+
moduleInRefToOutRef=
41+
letf1(x:outref<'T>)=1
42+
letf2(x:inref<'T>)= f1&x// not allowed
43+
44+
moduleInRefToByRefClassMethod=
45+
typeC()=
46+
static memberf1(x:byref<'T>)=1
47+
letf2(x:inref<'T>)= C.f1&x// not allowed
48+
49+
moduleInRefToOutRefClassMethod=
50+
typeC()=
51+
static memberf1(x:outref<'T>)=1// not allowed
52+
letf2(x:inref<'T>)= C.f1&x
53+
54+
moduleInRefToByRefClassMethod2=
55+
typeC()=
56+
static memberf1(x:byref<'T>)=1
57+
letf2(x:inref<'T>)= C.f1(&x)// not allowed
58+
59+
moduleInRefToOutRefClassMethod2=
60+
typeC()=
61+
static memberf1(x:outref<'T>)=1// not allowed
62+
letf2(x:inref<'T>)= C.f1(&x)
63+
64+
moduleUseOfLibraryOnly=
65+
typeC()=
66+
static memberf1(x:byref<'T,'U>)=1
67+
#endif
2168

2269
// Test a simple ref argument
2370
moduleCompareExchangeTests=
@@ -1244,11 +1291,6 @@ module ByrefReturnMemberTests =
12441291
test()
12451292

12461293
moduleMatrixOfTests=
1247-
[<Struct>]
1248-
typeS=
1249-
[<DefaultValue(true)>]
1250-
val mutableX:int
1251-
12521294

12531295
moduleReturnAddressOfByRef=
12541296
letf1(x:byref<int>)=&x
@@ -1285,23 +1327,13 @@ module ByrefReturnMemberTests =
12851327
moduleWriteToByRef=
12861328
letf1(x:byref<int>)= x<-1
12871329

1288-
#if NEGATIVE
1289-
moduleWriteToInRef=
1290-
letf1(x:inref<int>)= x<-1// not allowed
1291-
#endif
1292-
12931330
moduleWriteToOutRef=
12941331
letf1(x:outref<int>)= x<-1
12951332

12961333
//-----
12971334
moduleWriteToByRefStructInner=
12981335
letf1(x:byref<S>)= x.X<-1
12991336

1300-
#if NEGATIVE
1301-
moduleWriteToInRefStructInner=
1302-
letf1(x:inref<S>)= x.X<-1//not allowed
1303-
#endif
1304-
13051337
moduleWriteToOutRefStructInner=
13061338
letf1(x:outref<S>)= x.X<-1
13071339

@@ -1310,12 +1342,6 @@ module ByrefReturnMemberTests =
13101342
letf1(x:byref<'T>)=1
13111343
letf2(x:outref<'T>)= f1&x
13121344

1313-
#if NEGATIVE
1314-
moduleInRefToByRef=
1315-
letf1(x:byref<'T>)=1
1316-
letf2(x:inref<'T>)= f1&x// not allowed
1317-
#endif
1318-
13191345
moduleByRefToByRef=
13201346
letf1(x:byref<'T>)=1
13211347
letf2(x:byref<'T>)= f1&x
@@ -1328,12 +1354,6 @@ module ByrefReturnMemberTests =
13281354
letf1(x:outref<'T>)=1
13291355
letf2(x:outref<'T>)= f1&x
13301356

1331-
#if NEGATIVE
1332-
moduleInRefToOutRef=
1333-
letf1(x:outref<'T>)=1
1334-
letf2(x:inref<'T>)= f1&x// not allowed
1335-
#endif
1336-
13371357
moduleByRefToInRef=
13381358
letf1(x:inref<'T>)=1
13391359
letf2(x:byref<'T>)= f1&x
@@ -1352,13 +1372,6 @@ module ByrefReturnMemberTests =
13521372
static memberf1(x:byref<'T>)=1
13531373
letf2(x:outref<'T>)= C.f1&x
13541374

1355-
#if NEGATIVE
1356-
moduleInRefToByRefClassMethod=
1357-
typeC()=
1358-
static memberf1(x:byref<'T>)=1
1359-
letf2(x:inref<'T>)= C.f1&x// not allowed
1360-
#endif
1361-
13621375
moduleByRefToByRefClassMethod=
13631376
typeC()=
13641377
static memberf1(x:byref<'T>)=1
@@ -1374,13 +1387,6 @@ module ByrefReturnMemberTests =
13741387
static memberf1(x:outref<'T>)=1
13751388
letf2(x:outref<'T>)= C.f1&x
13761389

1377-
#if NEGATIVE
1378-
moduleInRefToOutRefClassMethod=
1379-
typeC()=
1380-
static memberf1(x:outref<'T>)=1// not allowed
1381-
letf2(x:inref<'T>)= C.f1&x
1382-
#endif
1383-
13841390
moduleByRefToInRefClassMethod=
13851391
typeC()=
13861392
static memberf1(x:inref<'T>)=1
@@ -1402,13 +1408,6 @@ module ByrefReturnMemberTests =
14021408
static memberf1(x:byref<'T>)=1
14031409
letf2(x:outref<'T>)= C.f1(&x)
14041410

1405-
#if NEGATIVE
1406-
moduleInRefToByRefClassMethod2=
1407-
typeC()=
1408-
static memberf1(x:byref<'T>)=1
1409-
letf2(x:inref<'T>)= C.f1(&x)// not allowed
1410-
#endif
1411-
14121411
moduleByRefToByRefClassMethod2=
14131412
typeC()=
14141413
static memberf1(x:byref<'T>)=1
@@ -1424,13 +1423,6 @@ module ByrefReturnMemberTests =
14241423
static memberf1(x:outref<'T>)=1
14251424
letf2(x:outref<'T>)= C.f1(&x)
14261425

1427-
#if NEGATIVE
1428-
moduleInRefToOutRefClassMethod2=
1429-
typeC()=
1430-
static memberf1(x:outref<'T>)=1// not allowed
1431-
letf2(x:inref<'T>)= C.f1(&x)
1432-
#endif
1433-
14341426
moduleByRefToInRefClassMethod2=
14351427
typeC()=
14361428
static memberf1(x:inref<'T>)=1
@@ -1445,12 +1437,6 @@ module ByrefReturnMemberTests =
14451437
typeC()=
14461438
static memberf1(x:inref<'T>)=1
14471439
letf2(x:outref<'T>)= C.f1(&x)
1448-
1449-
#if NEGATIVE
1450-
moduleUseOfLibraryOnly=
1451-
typeC()=
1452-
static memberf1(x:byref<'T,'U>)=1
1453-
#endif
14541440

14551441
letaa=
14561442
if!failuresthen(stdout.WriteLine"Test Failed"; exit1)

‎tests/fsharp/tests.fs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ module CoreTests =
182182

183183
fsc cfg"%s -o:test.exe -g" cfg.fsc_flags["test.fsx"]
184184

185+
singleNegTest cfg"test"
186+
185187
exec cfg("."++"test.exe")""
186188

187189
testOkFile.CheckExists()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp