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

Commitb99f487

Browse files
authored
Disallow byref field on IsByRefLike structs (#5103)
* Disallow byref field on IsByRefLike structs* Added test for IsByRefLike on a struct. Updated baselines
1 parente6c2a38 commitb99f487

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

‎src/fsharp/PostInferenceChecks.fs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,10 +1543,12 @@ let CheckRecdField isUnion cenv env (tycon:Tycon) (rfield:RecdField) =
15431543
(not isUnion&& IsHiddenRecdField env.sigToImplRemapInfo(tcref.MakeNestedRecdFieldRef rfield))
15441544
letaccess= AdjustAccess isHidden(fun()-> tycon.CompilationPath) rfield.Accessibility
15451545
CheckTypeForAccess cenv env(fun()-> rfield.Name) access m rfield.FormalType
1546-
1546+
15471547
if TyconRefHasAttribute g m g.attrib_IsByRefLikeAttribute tcrefthen
15481548
// Permit Span fields in IsByRefLike types
15491549
CheckTypePermitOuterSpanLike cenv env m rfield.FormalType
1550+
if cenv.reportErrorsthen
1551+
CheckForByrefType cenv env rfield.FormalType(fun()-> errorR(Error(FSComp.SR.chkCantStoreByrefValue(), tycon.Range)))
15501552
else
15511553
CheckTypeNoByrefs cenv env m rfield.FormalType
15521554
if cenv.reportErrorsthen

‎tests/fsharp/typecheck/sigs/neg107.bsl‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ neg107.fsx(53,34,53,38): typecheck error FS3234: Struct members cannot return th
6464
neg107.fsx(67,34,67,40): typecheck error FS3234: Struct members cannotreturn the address of fields of the struct by reference
6565

6666
neg107.fsx(67,34,67,38): typecheck error FS3234: Struct members cannotreturn the address of fields of the struct by reference
67+
68+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This isnot permitted by the rules of Common IL.
69+
70+
neg107.fsx(71,14,71,18): typecheck error FS0437: A type would store a byref typed value. This isnot permitted by Common IL.
71+
72+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This isnot permitted by the rules of Common IL.
73+
74+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This isnot permitted by the rules of Common IL.
75+
76+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This isnot permitted by the rules of Common IL.

‎tests/fsharp/typecheck/sigs/neg107.fsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@ namespace Test
6565
val mutablex:TestMut1
6666

6767
memberthis.XAddr=&this.x.x// not allowed, Struct members cannot return the address of fields of the struct by reference", not entirely clear why C# disallowed this
68+
69+
moduleDisallowIsByRefLikeWithByRefField=
70+
[<IsByRefLike;Struct>]
71+
typeBeef(x:byref<int>)=
72+
73+
member__.X=&x
74+

‎tests/fsharp/typecheck/sigs/neg107.vsbsl‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ neg107.fsx(53,34,53,38): typecheck error FS3234: Struct members cannot return th
6464
neg107.fsx(67,34,67,40): typecheck error FS3234: Struct members cannot return the address of fields of the struct by reference
6565

6666
neg107.fsx(67,34,67,38): typecheck error FS3234: Struct members cannot return the address of fields of the struct by reference
67+
68+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This is not permitted by the rules of Common IL.
69+
70+
neg107.fsx(71,14,71,18): typecheck error FS0437: A type would store a byref typed value. This is not permitted by Common IL.
71+
72+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This is not permitted by the rules of Common IL.
73+
74+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This is not permitted by the rules of Common IL.
75+
76+
neg107.fsx(71,19,71,20): typecheck error FS0412: A type instantiation involves a byref type. This is not permitted by the rules of Common IL.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp