Skip to content

Roslyn didn't report "Cast is redundant" for as in CSharp #41858

@yyjdelete

Description

@yyjdelete

Version Used:
16.5 preview3

Steps to Reproduce:

using System;
public class C {
    public string M1(string obj) {
        return (string)obj;
    }
    public string M2(string obj) {
        return obj as string;
    }
}

Expected Behavior:
The as string in M2 should also be reported as unnessary as it does in M1.
And it does work for Visual Basic
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AbEA3YaAmIA1AD4AKArsBgJZgAEAwhgIYDObTAsAFD3/1K1OvQBiFAHZgALjQgT6AWQCMACgBCATwBqLDPQjAAVvQCCnAMrSoNCQHMAlGcvXbd3gM/0ASjGkUoBUMjDwEAUQl8MUkZOQleUP4hWgZxKVl5JQAmDR09A2NneisbeydzYtd7RK9ff0D6ABUoTUZ2aVVgtErSxxqIqLTY+V4BplYOXiA=

Actual Behavior:
The as string in M2 is not reported as unnessary in source code, but seems compiler already know that and it's included in output IL.

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions