[英]F# byref param not mutable
I need to assign to a byref parameter, but, using F# 4.0 and .NET 4.5.2 on a Windows 8x64 box, I keep getting complaints that This value is not mutable.
我需要分配一个byref参数,但是,在Windows 8x64的盒子上使用F#4.0和.NET 4.5.2,我一直抱怨
This value is not mutable.
I can't change the signature, because I'm implementing a COM interface. 我无法更改签名,因为我正在实现一个COM接口。 Minimal broken example:
最小的破碎的例子:
module Utils =
let bugFix1([<System.Runtime.InteropServices.Out>] ID : System.String byref) = ID <- "Hi!"
let bugFix1([<System.Runtime.InteropServices.Out>] ID : int byref) = ID <- 0
let bugFix1([<System.Runtime.InteropServices.Out>] ID : System.Guid byref) = ID <- System.Guid.NewGuid()
By this value
, it definitely means ID
, because it doesn't matter what I assign to ID
. 通过
this value
,它肯定意味着ID
,因为我分配给ID
并不重要。 Note too, that it doesn't matter whether the type is blittable or not, or whether it is heap- or stack-allocated. 另请注意,类型是否为blittable无关紧要,或者是堆分配还是堆栈分配无关紧要。
Is there some way do declare ID
as mutable
? 有没有办法将
ID
声明为mutable
?
I think you have discovered another bug (or undocumented feature?). 我想你已经发现了另一个bug(或未记录的功能?)。 This happens simply because your parameter name is capitalized.
这只是因为您的参数名称大写。 Surprise!
惊喜! :-)
:-)
These variants will work (omitted [<Out>]
for brevity): 这些变体将起作用(为简洁省略
[<Out>]
):
let bugFix1(id : string byref) = id <- "Hi!"
let bugFix1(iD : string byref) = iD <- "Hi!"
But these will fail: 但这些都会失败:
let bugFix1(Id : string byref) = Id <- "Hi!"
let bugFix1(ID : string byref) = ID <- "Hi!"
I have absolutely no idea why capitalization would matter. 我完全不知道为何资本化很重要。 I would guess that this never arose before, because parameters always start with a lower-case letter by convention.
我猜这个从未出现过,因为参数总是按照惯例以小写字母开头。
I intend to google some more and then file an issue. 我打算再谷歌一些,然后提出问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.