Implementing a new semantic error in the C# compiler code base
This section will enable the Roslyn contributor to make changes to the C# binder/semantic analysis phase to add a new semantic diagnostic. Additionally, we will also show how to extend an existing semantic diagnostic reported during the local rewriting (lowering) phase to cover more cases.
Usage of implicitly typed declarations with the var
keyword is a very subjective matter. The C# compiler only reports non-subjective semantic errors on implicitly typed declarations where the type cannot be inferred or is invalid. However, there are certain cases where the type of the initializer is valid and can be inferred, but not at all apparent due to conversions in the initializer expression. For example, consider the expressions var x = 1 + 1.0, var y = "string" + 1
. The initializers for x and y contain implicit conversions on the left/right sides of the binary expression, which may also involve user defined implicit operator conversions...