{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/31494","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/31494/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/31494/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/31494/events","html_url":"https://github.com/dotnet/roslyn/issues/31494","id":386575315,"node_id":"MDU6SXNzdWUzODY1NzUzMTU=","number":31494,"title":"Suboptimal constant pattern codegen","user":{"login":"alrz","id":3105979,"node_id":"MDQ6VXNlcjMxMDU5Nzk=","avatar_url":"https://avatars2.githubusercontent.com/u/3105979?v=4","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"labels":[{"id":166673288,"node_id":"MDU6TGFiZWwxNjY2NzMyODg=","url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Compilers","name":"Area-Compilers","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-02T16:29:27Z","updated_at":"2018-12-03T21:01:35Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"**Version Used**:  `features/recursive-patterns`\r\n\r\n**Steps to Reproduce**: Examples:\r\n\r\nhttps://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLRIMaOQSwG4SoAOsMECAdsgD4ACAjAGwAEtATK/QOwCwAUAG9+zEawDMnFsAD20gDbMAksgCCGeFDkAKBgAZmADwCUzALwA+Q8xzJmAIjsBuYaNoSGU2QuUBRA0Qh1CAATHXp9YzNLAzNTeycXEUTxSWYZeWYAZQB3HBgMAAsAJRC4CmCoChgAOTg5OQBhAsCAazCIkwsrZFz8guYBByjmGAQ4CAAaexU7YdHxqYB9KLBNZAgAX2c+UWZkt1T0hQAFBGkAhBgATzUNbQYAOgAVK4DDTujrWwFmaqgAWwgIHsDC4sy2+3cTDSXmYp3O5GufgCQVCjxeb0iXRiAEI4hQ6goAGREwwPP6A2Ig7gJHaiSGHWHKW5wTRaHBVAD872GMRszHojj2dJEBw8MIyvn8gTIoQ5MG5WM+pjigv4G34/CAA==\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/443868698","html_url":"https://github.com/dotnet/roslyn/issues/31494#issuecomment-443868698","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/31494","id":443868698,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0Mzg2ODY5OA==","user":{"login":"gafter","id":3804346,"node_id":"MDQ6VXNlcjM4MDQzNDY=","avatar_url":"https://avatars3.githubusercontent.com/u/3804346?v=4","gravatar_id":"","url":"https://api.github.com/users/gafter","html_url":"https://github.com/gafter","followers_url":"https://api.github.com/users/gafter/followers","following_url":"https://api.github.com/users/gafter/following{/other_user}","gists_url":"https://api.github.com/users/gafter/gists{/gist_id}","starred_url":"https://api.github.com/users/gafter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gafter/subscriptions","organizations_url":"https://api.github.com/users/gafter/orgs","repos_url":"https://api.github.com/users/gafter/repos","events_url":"https://api.github.com/users/gafter/events{/privacy}","received_events_url":"https://api.github.com/users/gafter/received_events","type":"User","site_admin":false},"created_at":"2018-12-03T21:01:35Z","updated_at":"2018-12-03T21:01:35Z","author_association":"MEMBER","body":"For reference, here is the source and decompiled code. The principal issue being reported is a redundant null check for a constant pattern.\r\n\r\nSource:\r\n``` c#\r\nstatic class Program\r\n{\r\n    public static bool IsActual(string x) => x is \"\";\r\n    public static bool IsExpected(string x) => x == \"\";\r\n    \r\n    public static bool SwitchRedundantNullCheck(string x) => x switch {\"\" => true, \"A\" => true, _ =>false};\r\n    \r\n    public static bool PropertyActual(System.Type x) => x is { Name: \"Program\" };\r\n    public static bool PropertyExpected(System.Type x) => x != null && x.Name == \"Program\";\r\n    \r\n    public static bool IsActual(int? x) => x is 1; \r\n    public static bool IsExpected(int? x) => x == 1;\r\n}\r\n```\r\n\r\nDecompiled:\r\n``` c#\r\ninternal static class Program\r\n{\r\n    public static bool IsActual(string x)\r\n    {\r\n        if (x != null)\r\n        {\r\n            return x == \"\";\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static bool IsExpected(string x)\r\n    {\r\n        return x == \"\";\r\n    }\r\n\r\n    public static bool SwitchRedundantNullCheck(string x)\r\n    {\r\n        if (x != null)\r\n        {\r\n            if (x != null && x.Length == 0)\r\n            {\r\n                return true;\r\n            }\r\n            if (x == \"A\")\r\n            {\r\n                return true;\r\n            }\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static bool PropertyActual(Type x)\r\n    {\r\n        if ((object)x != null)\r\n        {\r\n            string name = x.Name;\r\n            if (name != null)\r\n            {\r\n                return name == \"Program\";\r\n            }\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static bool PropertyExpected(Type x)\r\n    {\r\n        if (x != null)\r\n        {\r\n            return x.Name == \"Program\";\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static bool IsActual(int? x)\r\n    {\r\n        if (x.HasValue)\r\n        {\r\n            return x.GetValueOrDefault() == 1;\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static bool IsExpected(int? x)\r\n    {\r\n        int? num = x;\r\n        int num2 = 1;\r\n        return (num.GetValueOrDefault() == num2) & num.HasValue;\r\n    }\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"gafter"}}