You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Fixed extension members that extend a type using a byref to be called with an immutable value (#5447)
* Fixed extension members that extend a type using a byref to be called with an immutable value
* Added more tests, but no updated baseline yet
* Updated baselines
* Minor cleanup
* Fixed tests. Fixed output of tests
* Updated buildfromsource
* Minor cleanup
Copy file name to clipboardExpand all lines: src/buildfromsource/FSharp.Compiler.Private/FSComp.fs
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -4327,33 +4327,33 @@ type internal SR private() =
4327
4327
/// The address of a value returned from the expression cannot be used at this point. This is to ensure the address of the local value does not escape its scope.
/// The Span or IsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope.
/// This value can't be assigned because the target '%s' may refer to non-stack-local memory, while the expression being assigned is assessed to potentially refer to stack-local memory. This is to help prevent pointers to stack-bound memory escaping their scope.
/// The function or method call cannot be used at this point, because one argument that is a byref of a non-stack-local Span or IsByRefLike type is used with another argument that is a stack-local Span or IsByRefLike type. This is to ensure the address of the local value does not escape its scope.
/// 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.
<value>The address of a value returned from the expression cannot be used at this point. This is to ensure the address of the local value does not escape its scope.</value>
<value>The Span or IsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope.</value>
<value>This value can't be assigned because the target '{0}' may refer to non-stack-local memory, while the expression being assigned is assessed to potentially refer to stack-local memory. This is to help prevent pointers to stack-bound memory escaping their scope.</value>
4338
4335
</data>
@@ -4343,7 +4340,7 @@
4343
4340
<value>A type annotated with IsReadOnly must also be a struct. Consider adding the [<Struct>] attribute to the type.</value>
<value>The function or method call cannot be used at this point, because one argument that is a byref of a non-stack-local Span or IsByRefLike type is used with another argument that is a stack-local Span or IsByRefLike type. This is to ensure the address of the local value does not escape its scope.</value>
<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>
<value>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.</value>
Copy file name to clipboardExpand all lines: src/fsharp/FSComp.txt
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1438,4 +1438,5 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
1438
1438
3233,chkNoByrefLikeFunctionCall,"The function or method call cannot be used at this point, because one argument that is a byref of a non-stack-local Span or IsByRefLike type is used with another argument that is a stack-local Span or IsByRefLike type. This is to ensure the address of the local value does not escape its scope."
1439
1439
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."
1440
1440
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."
1441
-
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."
1441
+
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 extension member as it requires the value to be mutable or a byref type due to the extending type being used as a byref."
Copy file name to clipboardExpand all lines: src/fsharp/infos.fs
+25-11Lines changed: 25 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -284,13 +284,26 @@ let ExistsHeadTypeInEntireHierarchy g amap m typeToSearchFrom tcrefToLookFor =
284
284
letImportILTypeFromMetadata amap m scoref tinst minst ilty =
285
285
ImportILType scoref amap m (tinst@minst) ilty
286
286
287
-
288
-
/// Get the return type of an IL method, taking into account instantiations for type and method generic parameters, and
287
+
/// Read an Abstract IL type from metadata, including any attributes that may affect the type itself, and convert to an F# type.
288
+
letImportILTypeFromMetadataWithAttributes amap m scoref tinst minst ilty cattrs =
289
+
letty= ImportILType scoref amap m (tinst@minst) ilty
290
+
// If the type is a byref and one of attributes from a return or parameter has IsReadOnly, then it's a inref.
291
+
if isByrefTy amap.g ty && TryFindILAttribute amap.g.attrib_IsReadOnlyAttribute cattrs then
292
+
mkInByrefTy amap.g (destByrefTy amap.g ty)
293
+
else
294
+
ty
295
+
296
+
/// Get the parameter type of an IL method.
297
+
letImportParameterTypeFromMetadata amap m ilty cattrs scoref tinst mist =
298
+
ImportILTypeFromMetadataWithAttributes amap m scoref tinst mist ilty cattrs
299
+
300
+
/// Get the return type of an IL method, taking into account instantiations for type, return attributes and method generic parameters, and
289
301
/// translating 'void' to 'None'.
290
-
letImportReturnTypeFromMetaData amap m ty scoref tinst minst =
291
-
matchtywith
302
+
letImportReturnTypeFromMetadata amap m ilty cattrs scoref tinst minst =
303
+
matchiltywith
292
304
| ILType.Void -> None
293
-
| retTy -> Some (ImportILTypeFromMetadata amap m scoref tinst minst retTy)
305
+
| retTy -> Some(ImportILTypeFromMetadataWithAttributes amap m scoref tinst minst retTy cattrs)
306
+
294
307
295
308
/// Copy constraints. If the constraint comes from a type parameter associated
296
309
/// with a type constructor then we are simply renaming type variables. If it comes
@@ -806,19 +819,19 @@ type ILMethInfo =
806
819
/// Get the argument types of the the IL method. If this is an C#-style extension method
807
820
/// then drop the object argument.
808
821
memberx.GetParamTypes(amap,m,minst)=
809
-
x.ParamMetadata |> List.map (fun p ->ImportILTypeFromMetadata amap m x.MetadataScope x.DeclaringTypeInst minst p.Type)
822
+
x.ParamMetadata |> List.map (fun p ->ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst)
810
823
811
824
/// Get all the argument types of the IL method. Include the object argument even if this is
812
825
/// an C#-style extension method.
813
826
memberx.GetRawArgTypes(amap,m,minst)=
814
-
x.RawMetadata.Parameters |> List.map (fun p ->ImportILTypeFromMetadata amap m x.MetadataScope x.DeclaringTypeInst minst p.Type)
827
+
x.RawMetadata.Parameters |> List.map (fun p ->ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst)
815
828
816
829
/// Get info about the arguments of the IL method. If this is an C#-style extension method then
817
830
/// drop the object argument.
818
831
///
819
832
/// Any type parameters of the enclosing type are instantiated in the type returned.
820
833
memberx.GetParamNamesAndTypes(amap,m,minst)=
821
-
x.ParamMetadata |> List.map (fun p -> ParamNameAndType(Option.map (mkSynId m) p.Name,ImportILTypeFromMetadata amap m x.MetadataScope x.DeclaringTypeInst minst p.Type))
834
+
x.ParamMetadata |> List.map (fun p -> ParamNameAndType(Option.map (mkSynId m) p.Name,ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst))
822
835
823
836
/// Get a reference to the method (dropping all generic instantiations), as an Abstract IL ILMethodRef.
824
837
memberx.ILMethodRef=
@@ -838,15 +851,16 @@ type ILMethInfo =
838
851
// All C#-style extension methods are instance. We have to re-read the 'obj' type w.r.t. the
839
852
// method instantiation.
840
853
if x.IsILExtensionMethod then
841
-
[ImportILTypeFromMetadata amap m x.MetadataScope x.DeclaringTypeInst minst x.RawMetadata.Parameters.Head.Type]
854
+
letp= x.RawMetadata.Parameters.Head
855
+
[ ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst ]
842
856
elseif x.IsInstance then
843
857
[ x.ApparentEnclosingType ]
844
858
else
845
859
[]
846
860
847
861
/// Get the compiled return type of the method, where 'void' is None.
848
862
memberx.GetCompiledReturnTy(amap,m,minst)=
849
-
ImportReturnTypeFromMetaData amap m x.RawMetadata.Return.Type x.MetadataScope x.DeclaringTypeInst minst
863
+
ImportReturnTypeFromMetadata amap m x.RawMetadata.Return.Type x.RawMetadata.Return.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst
850
864
851
865
/// Get the F# view of the return type of the method, where 'void' is 'unit'.
852
866
memberx.GetFSharpReturnTy(amap,m,minst)=
@@ -1503,7 +1517,7 @@ type MethInfo =
1503
1517
match x with
1504
1518
| ILMeth(_,ilminfo,_)->
1505
1519
letftinfo= ILTypeInfo.FromType g (TType_app(tcref,formalEnclosingTyparTys))
1506
-
letformalRetTy=ImportReturnTypeFromMetaData amap m ilminfo.RawMetadata.Return.Type ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys
1520
+
letformalRetTy=ImportReturnTypeFromMetadata amap m ilminfo.RawMetadata.Return.Type ilminfo.RawMetadata.Return.CustomAttrs ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys
1507
1521
letformalParams=
1508
1522
[[for p in ilminfo.RawMetadata.Parameters do
1509
1523
letparamType= ImportILTypeFromMetadata amap m ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys p.Type
Copy file name to clipboardExpand all lines: src/fsharp/xlf/FSComp.txt.cs.xlf
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7057,6 +7057,11 @@
7057
7057
<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>
<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>
Copy file name to clipboardExpand all lines: src/fsharp/xlf/FSComp.txt.de.xlf
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7057,6 +7057,11 @@
7057
7057
<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>
<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>
0 commit comments