Priority
Show-stopper
Type
Bug 
State
Won't fix 
Assignee
Eugene Pasynkov 
Subsystem
No subsystem 
Affected versions
Fixed in
Fixed in build
Next build 
Build
240
  • Submitted by   Boris Kartamyshev
    3 years ago (06 Aug 2006 17:28)
  • Updated by Boris Kartamyshev
    3 years ago (09 Sep 2006 13:33)
  • Jira: RSRP-25232
    (history, comments)

RSRP-25232

Invalid handling of conditional operator. R# always shows error when none exists

0
In following code:

public abstract class A {}
public class B : A {}
public class C : A {}
public class D
{
    public A GetClass(char className)
    {
        return className == 'B' ? 
               new B() : 
               className == 'C' ? new C() : null;
    }
}


R# highlights entire return expression and displays following error message: There is no implicit conversion between 'B' and 'C' which is true but return type is neither 'B' nor 'C' - it 'A' thus error is inappropriate.

Error can be removed by adding manual casting to (A):

public abstract class A {}
public class B : A {}	
public class C : A {}
public class D
{
    public A GetClass(char className)
    {
        return className == 'B' ? 
               (A)new B() : 
               className == 'C' ? (A)new C() : null;
    }
}


But then R# grays out (A) and warning says 'Type cast is redundant' which is correct. But since removing (A) brings us back error message from above, file never gets green light (it can be either red or orange).

Issue was closed
Comments (0)
 
History (0)
 
Links
 
Issue has no comments