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

Commit0257ff1

Browse files
dsymeKevinRansom
authored andcommitted
Fix part of 3465 - allow nativeptr address in 'let x = &&expr' (#3525)
* Fix part of 3465 - allow nativeptr address of in 'let'* fix tests* fix test* fix test
1 parente4c09f7 commit0257ff1

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

‎src/fsharp/PostInferenceChecks.fs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ and CheckExpr (cenv:cenv) (env:env) expr (context:ByrefContext) =
624624
CheckExprsPermitByrefs cenv env rest
625625

626626
| Expr.Op(c,tyargs,args,m)->
627-
CheckExprOp cenv env(c,tyargs,args,m) context
627+
CheckExprOp cenv env(c,tyargs,args,m) context expr
628628

629629
// Allow 'typeof<System.Void>' calls as a special case, the only accepted use of System.Void!
630630
| TypeOfExpr cenv.g tywhen isVoidTy cenv.g ty->
@@ -734,7 +734,7 @@ and CheckInterfaceImpls cenv env baseValOpt l =
734734
andCheckInterfaceImpl cenv env baseValOpt(_ty,overrides)=
735735
CheckMethods cenv env baseValOpt overrides
736736

737-
andCheckExprOp cenv env(op,tyargs,args,m)context=
737+
andCheckExprOp cenv env(op,tyargs,args,m)contextexpr=
738738
letlimitedCheck()=
739739
if env.limitedthen errorR(Error(FSComp.SR.chkObjCtorsCantUseExceptionHandling(), m))
740740
List.iter(CheckTypePermitByrefs cenv env m) tyargs
@@ -828,13 +828,13 @@ and CheckExprOp cenv env (op,tyargs,args,m) context =
828828
CheckTypeInstNoByrefs cenv env m tyargs
829829

830830
| TOp.ValFieldGetAddr rfref,tyargs,[]->
831-
if noByrefs context&& cenv.reportErrorsthen
831+
if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g(tyOfExpr cenv.g expr)then
832832
errorR(Error(FSComp.SR.chkNoAddressStaticFieldAtThisPoint(rfref.FieldName), m))
833833
CheckTypeInstNoByrefs cenv env m tyargs
834834
// NOTE: there are no arg exprs to check in this case
835835

836836
| TOp.ValFieldGetAddr rfref,tyargs,[rx]->
837-
if noByrefs context&& cenv.reportErrorsthen
837+
if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g(tyOfExpr cenv.g expr)then
838838
errorR(Error(FSComp.SR.chkNoAddressFieldAtThisPoint(rfref.FieldName), m))
839839
// This construct is used for &(rx.rfield) and &(rx->rfield). Relax to permit byref types for rx. [See Bug 1263].
840840
CheckTypeInstNoByrefs cenv env m tyargs
@@ -849,7 +849,7 @@ and CheckExprOp cenv env (op,tyargs,args,m) context =
849849
CheckExprPermitByref cenv env arg1// allow byref - it may be address-of-struct
850850

851851
| TOp.UnionCaseFieldGetAddr(uref,_idx),tyargs,[rx]->
852-
if noByrefs context&& cenv.reportErrorsthen
852+
if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g(tyOfExpr cenv.g expr)then
853853
errorR(Error(FSComp.SR.chkNoAddressFieldAtThisPoint(uref.CaseName), m))
854854
CheckTypeInstNoByrefs cenv env m tyargs
855855
// allow rx to be byref here, for struct unions
@@ -870,12 +870,12 @@ and CheckExprOp cenv env (op,tyargs,args,m) context =
870870
// permit byref for lhs lvalue of readonly value
871871
CheckExprPermitByref cenv env lhs
872872
|[ I_ldflda(fspec)| I_ldsflda(fspec)],[lhs]->
873-
if noByrefs context&& cenv.reportErrorsthen
873+
if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g(tyOfExpr cenv.g expr)then
874874
errorR(Error(FSComp.SR.chkNoAddressFieldAtThisPoint(fspec.Name), m))
875875
// permit byref for lhs lvalue
876876
CheckExprPermitByref cenv env lhs
877877
|[ I_ldelema(_,isNativePtr,_,_)],lhsArray::indices->
878-
ifnot(isNativePtr)&&noByrefs context&& cenv.reportErrorsthen
878+
ifnoByrefs context&&cenv.reportErrors&&not isNativePtr&&isByrefLikeTycenv.g(tyOfExpr cenv.g expr)then
879879
errorR(Error(FSComp.SR.chkNoAddressOfArrayElementAtThisPoint(), m))
880880
// permit byref for lhs lvalue
881881
CheckExprPermitByref cenv env lhsArray
@@ -982,7 +982,7 @@ and CheckLambdas isTop (memInfo: ValMemberInfo option) cenv env inlined topValIn
982982
|_->
983983
// Permit byrefs for let x = ...
984984
CheckTypePermitByrefs cenv env m ety
985-
ifnot inlined&& isByrefLikeTy cenv.g etythen
985+
ifnot inlined&&(isByrefLikeTy cenv.g ety|| isNativePtrTy cenv.g ety)then
986986
// allow byref to occur as RHS of byref binding.
987987
CheckExprPermitByref cenv env e
988988
else

‎tests/fsharp/tests.fs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,12 @@ module TypecheckTests =
16811681

16821682
peverify cfg"pos27.exe"
16831683

1684+
[<Test>]
1685+
let``sigs pos28``()=
1686+
letcfg= testConfig"typecheck/sigs"
1687+
fsc cfg"%s --target:exe -o:pos28.exe" cfg.fsc_flags["pos28.fs"]
1688+
peverify cfg"pos28.exe"
1689+
16841690
[<Test>]
16851691
let``sigs pos26``()=
16861692
letcfg= testConfig"typecheck/sigs"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
modulePos28
2+
3+
openFSharp.NativeInterop
4+
5+
moduleTest1=
6+
[<Struct>]
7+
typePoint=
8+
val mutableX:int
9+
val mutableY:int
10+
new(x,y)={ X=x; Y=y;}
11+
12+
letfixPoint1()=
13+
let mutablepoint= Point(1,2)
14+
letp1=&&point.X
15+
NativePtr.read<int> p1
16+
17+
moduleTest2=
18+
[<Struct>]
19+
typePoint={mutable x:int;mutable y:int}
20+
21+
letfixPoint1()=
22+
let mutablepoint= Unchecked.defaultof<Point>
23+
letp1=&&point.x
24+
NativePtr.read<int> p1
25+

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/AddressOf/E_byrefvaluesnotpermitted002.fs‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/AddressOf/env.lst‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ NoMTSOURCE=addressof001.fsx PRECMD="\$CSC_PIPE /t:library addressof001dll.cs"
33
NoMTSOURCE=addressof002.fsx PRECMD="\$CSC_PIPE /t:library addressof002dll.cs"# addressof002.fsx
44
NOMONOSOURCE=addressof003.fs SCFLAGS="--test:ErrorRanges" PRECMD="copy /y addressof003dll_%OSARCH%.dll addressof003dll.dll" PEVER=/MD# addressof003.fs
55
SOURCE=E_byrefvaluesnotpermitted001.fs SCFLAGS="--test:ErrorRanges"# E_byrefvaluesnotpermitted001.fs
6-
SOURCE=E_byrefvaluesnotpermitted002.fs SCFLAGS="--test:ErrorRanges"# E_byrefvaluesnotpermitted002.fs

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp