How can I satisfy the compiler to eliminate warning 0052?

I have a desire to satisfy compiler 5 warning level. Thus, I have 32 warnings in a single file FS0052. The value was copied to ensure that the original will not be altered by this operation.

I have been following the only SO message that seems to be related to this warning, but since my type is a type provider created by Microsoft, I cannot just go to the mutable field to disable the warning. plus doing something mutable, which really should never be mutated, seems like a crack is not a fix.

examples:

  • Nullable .GetValueOrDefault()
  • Nullable .ToString()
  • Guide .ToString()
  • a call to a structure method of any type that I consider

What is the recommended way to deal with this warning from an appropriate functional point of view?

+4
source share
2 answers

Not sure if you are still interested.

It seems to me that the compiler gives a warning when it is not sure whether the method call is going to destroy the state of the original instance (this should come mainly from any library outside of F #).

An explicit copy of the value into a variable, in my case, often mitigates the warning. For instance:

open System

// generate the warning due to "ToString()"
let DirSeparator = Path.DirectorySeparatorChar.ToString()  

// no warning
let ExplicitCopy = let x = Path.DirectorySeparatorChar in x.ToString()  

let Alternative = sprintf "%c" Path.DirectorySeparatorChar
+3
source

What is the recommended way to deal with this warning with a proper functional perspective?

, . .

, . ( - , , , . , , 5).

, .

,

myStruct.someField <- myRecord.SomeField.ToString()

myStruct.someField <- string myRecord.SomeField

- - , , , , , .

, GetValueOrDefault.

let valueOrDefault (v: 'a Nullable) = if v.HasValue then v.Value else Unchecked.defaultof<'a>

, , , . .

0

Source: https://habr.com/ru/post/1583770/


All Articles