>
>
>
V6042. The expression is checked for co…


V6042. The expression is checked for compatibility with type 'A', but is cast to type 'B'.

The analyzer detected a likely error that has to do with checking if an expression is compatible with one type and casting it to another type inside the body of the conditional statement.

Consider the following example:

if (a instanceof A) 
{
  return (B)a;
}

The programmer must have made a mistake, since a type conversion like that is very likely to cause a bug. What was actually meant is either to check the expression for type 'B' or cast it to type 'A'.

This is what the correct version could look like:

if (a instanceof B) 
{
  return (B)a;
}

This diagnostic is classified as:

You can look at examples of errors detected by the V6042 diagnostic.