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

Commitc71aa9f

Browse files
authored
Fixed crash for unapplied byref extension methods; also disallowing them. (dotnet#5492)
* Fixed crash. Disallowing unapplied byref exstension methods. Updated some erorr messages.* Updated some tests* Quick update on method name* Updated buildfromsource* Updated error message* Renamed method
1 parent0e85dd1 commitc71aa9f

23 files changed

+190
-105
lines changed

‎src/buildfromsource/FSharp.Compiler.Private/FSComp.fs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,12 +4351,15 @@ type internal SR private() =
43514351
/// Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.
43524352
/// (Originally from ..\FSComp.txt:1441)
43534353
static membertastCantTakeAddressOfExpression()=(3236, GetStringFunc("tastCantTakeAddressOfExpression",",,,"))
4354-
/// Cannot call the extensionmember as itrequires the value to be mutable or a byref type due to the extending type being used as a byref.
4354+
/// Cannot call thebyrefextensionmethod '%s. The first parameterrequires the value to be mutable or anon-readonlybyref type.
43554355
/// (Originally from ..\FSComp.txt:1442)
4356-
static membertcCannotCallExtensionMemberInrefToByref()=(3237, GetStringFunc("tcCannotCallExtensionMemberInrefToByref",",,,"))
4356+
static membertcCannotCallExtensionMethodInrefToByref(a0:System.String)=(3237, GetStringFunc("tcCannotCallExtensionMethodInrefToByref",",,,%s,,,")a0)
43574357
/// Byref types are not allowed to have optional type extensions.
43584358
/// (Originally from ..\FSComp.txt:1443)
43594359
static membertcByrefsMayNotHaveTypeExtensions()=(3238, GetStringFunc("tcByrefsMayNotHaveTypeExtensions",",,,"))
4360+
/// Cannot partially apply the extension method '%s' because the first parameter is a byref type.
4361+
/// (Originally from ..\FSComp.txt:1444)
4362+
static membertcCannotPartiallyApplyExtensionMethodForByref(a0:System.String)=(3239, GetStringFunc("tcCannotPartiallyApplyExtensionMethodForByref",",,,%s,,,") a0)
43604363

43614364
/// Call this method once to validate that all known resources are valid; throws if not
43624365
static memberRunStartupValidation()=
@@ -5772,6 +5775,7 @@ type internal SR private() =
57725775
ignore(GetString("chkNoSpanLikeVariable"))
57735776
ignore(GetString("chkNoSpanLikeValueFromExpression"))
57745777
ignore(GetString("tastCantTakeAddressOfExpression"))
5775-
ignore(GetString("tcCannotCallExtensionMemberInrefToByref"))
5778+
ignore(GetString("tcCannotCallExtensionMethodInrefToByref"))
57765779
ignore(GetString("tcByrefsMayNotHaveTypeExtensions"))
5780+
ignore(GetString("tcCannotPartiallyApplyExtensionMethodForByref"))
57775781
()

‎src/buildfromsource/FSharp.Compiler.Private/FSComp.resx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,10 +4354,13 @@
43544354
<dataname="tastCantTakeAddressOfExpression"xml:space="preserve">
43554355
<value>Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.</value>
43564356
</data>
4357-
<dataname="tcCannotCallExtensionMemberInrefToByref"xml:space="preserve">
4358-
<value>Cannot call the extensionmember as itrequires the value to be mutable or a byref type due to the extending type being used as a byref.</value>
4357+
<dataname="tcCannotCallExtensionMethodInrefToByref"xml:space="preserve">
4358+
<value>Cannot call thebyrefextensionmethod '{0}. The first parameterrequires the value to be mutable or anon-readonlybyref type.</value>
43594359
</data>
43604360
<dataname="tcByrefsMayNotHaveTypeExtensions"xml:space="preserve">
43614361
<value>Byref types are not allowed to have optional type extensions.</value>
43624362
</data>
4363+
<dataname="tcCannotPartiallyApplyExtensionMethodForByref"xml:space="preserve">
4364+
<value>Cannot partially apply the extension method '{0}' because the first parameter is a byref type.</value>
4365+
</data>
43634366
</root>

‎src/fsharp/FSComp.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,5 +1439,6 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
14391439
3234,chkNoSpanLikeVariable,"The Span or IsByRefLike variable '%s' cannot be used at this point. This is to ensure the address of the local value does not escape its scope."
14401440
3235,chkNoSpanLikeValueFromExpression,"A Span or IsByRefLike value returned from the expression cannot be used at ths point. This is to ensure the address of the local value does not escape its scope."
14411441
3236,tastCantTakeAddressOfExpression,"Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address."
1442-
3237,tcCannotCallExtensionMemberInrefToByref,"Cannot call the extensionmember as itrequires the value to be mutable or a byref type due to the extending type being used as a byref."
1442+
3237,tcCannotCallExtensionMethodInrefToByref,"Cannot call thebyrefextensionmethod '%s. The first parameterrequires the value to be mutable or anon-readonlybyref type."
14431443
3238,tcByrefsMayNotHaveTypeExtensions,"Byref types are not allowed to have optional type extensions."
1444+
3239,tcCannotPartiallyApplyExtensionMethodForByref,"Cannot partially apply the extension method '%s' because the first parameter is a byref type."

‎src/fsharp/MethodCalls.fs‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -598,28 +598,12 @@ let TakeObjAddrForMethodCall g amap (minfo:MethInfo) isMutable m objArgs f =
598598
// Check to see if the extension member uses the extending type as a byref.
599599
// If so, make sure we don't allow readonly/immutable values to be passed byref from an extension member.
600600
// An inref will work though.
601-
if mustTakeAddress&& isReadOnly&& minfo.IsExtensionMemberthen
602-
lettyOpt=
603-
match minfowith
604-
// For F# defined methods.
605-
| FSMeth(_,_, vref,_)->
606-
letty,_= destFunTy g vref.Type
607-
Some(ty)
608-
609-
// For IL methods, defined outside of F#.
610-
| ILMeth(_, info,_)->
611-
letparamTypes= info.GetRawArgTypes(amap, m, minfo.FormalMethodInst)
612-
match paramTypeswith
613-
|[]-> failwith"impossible"
614-
| ty::_-> Some(ty)
615-
616-
|_-> None
617-
618-
match tyOptwith
619-
| Some(ty)->
620-
if isByrefTy g ty&&not(isInByrefTy g ty)then
621-
errorR(Error(FSComp.SR.tcCannotCallExtensionMemberInrefToByref(), m))
622-
|_->()
601+
if isReadOnly&& mustTakeAddress&& minfo.IsExtensionMemberthen
602+
minfo.TryObjArgByrefType(amap, m, minfo.FormalMethodInst)
603+
|> Option.iter(fun ty->
604+
ifnot(isInByrefTy g ty)then
605+
errorR(Error(FSComp.SR.tcCannotCallExtensionMethodInrefToByref(minfo.DisplayName), m)))
606+
623607

624608
wrap,[objArgExpr']
625609

‎src/fsharp/PostInferenceChecks.fs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,8 +1776,6 @@ let CheckModuleBinding cenv env (TBind(v,e,_) as bind) =
17761776
MethInfosEquivByNameAndSig EraseAlltrue g cenv.amap v.Range minfo1 minfo2then
17771777
errorR(Duplicate(kind,v.DisplayName,v.Range)))
17781778

1779-
1780-
17811779
// Properties get 'get_X', only if there are no args
17821780
// Properties get 'get_X'
17831781
match v.ValReprInfowith

‎src/fsharp/TypeChecker.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9808,10 +9808,11 @@ and TcMethodApplication
98089808
let objArgPreBinder, objArgs =
98099809
match objArgs, lambdaVars with
98109810
| [objArg], Some _ ->
9811+
if finalCalledMethInfo.IsExtensionMember && finalCalledMethInfo.ObjArgNeedsAddress(cenv.amap, mMethExpr) then
9812+
error(Error(FSComp.SR.tcCannotPartiallyApplyExtensionMethodForByref(finalCalledMethInfo.DisplayName), mMethExpr))
98119813
let objArgTy = tyOfExpr cenv.g objArg
98129814
let v, ve = mkCompGenLocal mMethExpr "objectArg" objArgTy
98139815
(fun body -> mkCompGenLet mMethExpr v objArg body), [ve]
9814-
98159816
| _ ->
98169817
emptyPreBinder, objArgs
98179818

‎src/fsharp/infos.fs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,14 @@ type MethInfo =
15951595
|_->
15961596
x.DeclaringTyconRef.Typars(m)
15971597

1598+
/// Tries to get the object arg type if it's a byref type.
1599+
memberx.TryObjArgByrefType(amap,m,minst)=
1600+
x.GetObjArgTypes(amap, m, minst)
1601+
|> List.tryHead
1602+
|> Option.bind(fun ty->
1603+
if isByrefTy x.TcGlobals tythen Some(ty)
1604+
else None)
1605+
15981606
//-------------------------------------------------------------------------
15991607
// ILFieldInfo
16001608

‎src/fsharp/xlf/FSComp.txt.cs.xlf‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7057,16 +7057,21 @@
70577057
<targetstate="translated">Adresa hodnoty vrácená výrazem nejde převzít. Před převzetím adresy přiřaďte vrácenou hodnotu hodnotě s vazbou na klauzuli Let.</target>
70587058
<note />
70597059
</trans-unit>
7060-
<trans-unitid="tcCannotCallExtensionMemberInrefToByref">
7061-
<source>Cannot call the extension member as it requires the value to be mutable or a byref type due to the extending type being used as a byref.</source>
7062-
<targetstate="new">Cannot call the extension member as it requires the value to be mutable or a byref type due to the extending type being used as a byref.</target>
7063-
<note />
7064-
</trans-unit>
70657060
<trans-unitid="tcByrefsMayNotHaveTypeExtensions">
70667061
<source>Byref types are not allowed to have optional type extensions.</source>
70677062
<targetstate="new">Byref types are not allowed to have optional type extensions.</target>
70687063
<note />
70697064
</trans-unit>
7065+
<trans-unitid="tcCannotCallExtensionMethodInrefToByref">
7066+
<source>Cannot call the byref extension method '{0}. The first parameter requires the value to be mutable or a non-readonly byref type.</source>
7067+
<targetstate="new">Cannot call the byref extension method '{0}. The first parameter requires the value to be mutable or a non-readonly byref type.</target>
7068+
<note />
7069+
</trans-unit>
7070+
<trans-unitid="tcCannotPartiallyApplyExtensionMethodForByref">
7071+
<source>Cannot partially apply the extension method '{0}' because the first parameter is a byref type.</source>
7072+
<targetstate="new">Cannot partially apply the extension method '{0}' because the first parameter is a byref type.</target>
7073+
<note />
7074+
</trans-unit>
70707075
</body>
70717076
</file>
70727077
</xliff>

‎src/fsharp/xlf/FSComp.txt.de.xlf‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7057,16 +7057,21 @@
70577057
<target state="translated">Die Adresse des über den Ausdruck zurückgegebenen Werts kann nicht abgerufen werden. Weisen Sie den zurückgegebenen Wert einem let-bound-Wert zu, bevor Sie die Adresse abrufen.</target>
70587058
<note />
70597059
</trans-unit>
7060-
<trans-unit id="tcCannotCallExtensionMemberInrefToByref">
7061-
<source>Cannot call the extension member as it requires the value to be mutable or a byref type due to the extending type being used as a byref.</source>
7062-
<target state="new">Cannot call the extension member as it requires the value to be mutable or a byref type due to the extending type being used as a byref.</target>
7063-
<note />
7064-
</trans-unit>
70657060
<trans-unit id="tcByrefsMayNotHaveTypeExtensions">
70667061
<source>Byref types are not allowed to have optional type extensions.</source>
70677062
<target state="new">Byref types are not allowed to have optional type extensions.</target>
70687063
<note />
70697064
</trans-unit>
7065+
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">
7066+
<source>Cannot call the byref extension method '{0}. The first parameter requires the value to be mutable or a non-readonly byref type.</source>
7067+
<target state="new">Cannot call the byref extension method '{0}. The first parameter requires the value to be mutable or a non-readonly byref type.</target>
7068+
<note />
7069+
</trans-unit>
7070+
<trans-unit id="tcCannotPartiallyApplyExtensionMethodForByref">
7071+
<source>Cannot partially apply the extension method '{0}' because the first parameter is a byref type.</source>
7072+
<target state="new">Cannot partially apply the extension method '{0}' because the first parameter is a byref type.</target>
7073+
<note />
7074+
</trans-unit>
70707075
</body>
70717076
</file>
70727077
</xliff>

‎src/fsharp/xlf/FSComp.txt.en.xlf‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7057,16 +7057,21 @@
70577057
<targetstate="new">Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.</target>
70587058
<note />
70597059
</trans-unit>
7060-
<trans-unitid="tcCannotCallExtensionMemberInrefToByref">
7061-
<source>Cannot call the extension member as it requires the value to be mutable or a byref type due to the extending type being used as a byref.</source>
7062-
<targetstate="new">Cannot call the extension member as it requires the value to be mutable or a byref type due to the extending type being used as a byref.</target>
7063-
<note />
7064-
</trans-unit>
70657060
<trans-unitid="tcByrefsMayNotHaveTypeExtensions">
70667061
<source>Byref types are not allowed to have optional type extensions.</source>
70677062
<targetstate="new">Byref types are not allowed to have optional type extensions.</target>
70687063
<note />
70697064
</trans-unit>
7065+
<trans-unitid="tcCannotCallExtensionMethodInrefToByref">
7066+
<source>Cannot call the byref extension method '{0}. The first parameter requires the value to be mutable or a non-readonly byref type.</source>
7067+
<targetstate="new">Cannot call the byref extension method '{0}. The first parameter requires the value to be mutable or a non-readonly byref type.</target>
7068+
<note />
7069+
</trans-unit>
7070+
<trans-unitid="tcCannotPartiallyApplyExtensionMethodForByref">
7071+
<source>Cannot partially apply the extension method '{0}' because the first parameter is a byref type.</source>
7072+
<targetstate="new">Cannot partially apply the extension method '{0}' because the first parameter is a byref type.</target>
7073+
<note />
7074+
</trans-unit>
70707075
</body>
70717076
</file>
70727077
</xliff>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp