Search code examples
gosemanticsgoland

Delete conversion changes semantics


GoLand IDE by JetBrains offers automatic deletion of redundant type conversion. But there is a message:

Delete conversion (changes semantics)

I cannot figure out what is meant by changes semantics. What does it actually change?

Screenshot

Extra info:

More info


Solution

  • GoLand indeed shows Possibly redundant type conversion when an expression is of a floating type. In all other cases, the message is Redundant type conversion. The uncertainty in the former statement is connected to the fact that conversion from float to float is sometimes used to prevent the compiler's Fused Multiply Add (FMA) instruction selection to avoid rounding errors. Please refer to this issue for more details. I would agree, though, that changes semantic is perhaps too strict as a conversion result depends on many factors. So, I've changed the wording to may change semantics. I've also updated the inspection's description, so it contains this information. These changes will appear in GoLand 2020.3.