{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1840","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1840/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1840/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1840/events","html_url":"https://github.com/dotnet/csharplang/issues/1840","id":357956328,"node_id":"MDU6SXNzdWUzNTc5NTYzMjg=","number":1840,"title":"How do I tell the compiler that a type supports a specific interface?","user":{"login":"AlexRadch","id":6407980,"node_id":"MDQ6VXNlcjY0MDc5ODA=","avatar_url":"https://avatars1.githubusercontent.com/u/6407980?v=4","gravatar_id":"","url":"https://api.github.com/users/AlexRadch","html_url":"https://github.com/AlexRadch","followers_url":"https://api.github.com/users/AlexRadch/followers","following_url":"https://api.github.com/users/AlexRadch/following{/other_user}","gists_url":"https://api.github.com/users/AlexRadch/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexRadch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexRadch/subscriptions","organizations_url":"https://api.github.com/users/AlexRadch/orgs","repos_url":"https://api.github.com/users/AlexRadch/repos","events_url":"https://api.github.com/users/AlexRadch/events{/privacy}","received_events_url":"https://api.github.com/users/AlexRadch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-09-07T07:45:37Z","updated_at":"2018-09-07T14:08:08Z","closed_at":null,"author_association":"NONE","body":"I want to write the IndexOf method for `Span` and type `T` without limits: `public static int IndexOfEquals<T>(this Span<T> span, T value)`.\r\n\r\nYou can notice that if the type `T` implements the interface `IEquatable<T>` then for such `T` corresponding method is already exists and we just need to call it, but the compiler will not allow us to do that.\r\n\r\nNext code have incorrect casting `(T: IEquatable<T>)value`. How to make it correct?\r\n```cs\r\n        public static int IndexOfEquals<T>(this Span<T> span, T value)\r\n        {\r\n            if (typeof(IEquatable<T>).IsAssignableFrom(typeof(T)))\r\n                return System.MemoryExtensions.IndexOf(span, (T: IEquatable<T>)value);\r\n            // something else\r\n        }\r\n```\r\n\r\nHow can I call `System.MemoryExtensions.IndexOf` method in case if `T` type supports `IEquatable<T>` interface?"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/419450891","html_url":"https://github.com/dotnet/csharplang/issues/1840#issuecomment-419450891","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/1840","id":419450891,"node_id":"MDEyOklzc3VlQ29tbWVudDQxOTQ1MDg5MQ==","user":{"login":"svick","id":287848,"node_id":"MDQ6VXNlcjI4Nzg0OA==","avatar_url":"https://avatars3.githubusercontent.com/u/287848?v=4","gravatar_id":"","url":"https://api.github.com/users/svick","html_url":"https://github.com/svick","followers_url":"https://api.github.com/users/svick/followers","following_url":"https://api.github.com/users/svick/following{/other_user}","gists_url":"https://api.github.com/users/svick/gists{/gist_id}","starred_url":"https://api.github.com/users/svick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svick/subscriptions","organizations_url":"https://api.github.com/users/svick/orgs","repos_url":"https://api.github.com/users/svick/repos","events_url":"https://api.github.com/users/svick/events{/privacy}","received_events_url":"https://api.github.com/users/svick/received_events","type":"User","site_admin":false},"created_at":"2018-09-07T14:08:08Z","updated_at":"2018-09-07T14:08:08Z","author_association":"CONTRIBUTOR","body":"@jnm2 Possibly, though that seems to be geared towards specializing for a list of specific types, not for all types that satisfy a constraint."}}
{"actor":{"display_login":"svick"}}