{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/2146","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/2146/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/2146/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/2146/events","html_url":"https://github.com/dotnet/csharplang/issues/2146","id":399520828,"node_id":"MDU6SXNzdWUzOTk1MjA4Mjg=","number":2146,"title":"request: non-nullable type constraint","user":{"login":"Spongman","id":1088194,"node_id":"MDQ6VXNlcjEwODgxOTQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1088194?v=4","gravatar_id":"","url":"https://api.github.com/users/Spongman","html_url":"https://github.com/Spongman","followers_url":"https://api.github.com/users/Spongman/followers","following_url":"https://api.github.com/users/Spongman/following{/other_user}","gists_url":"https://api.github.com/users/Spongman/gists{/gist_id}","starred_url":"https://api.github.com/users/Spongman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Spongman/subscriptions","organizations_url":"https://api.github.com/users/Spongman/orgs","repos_url":"https://api.github.com/users/Spongman/repos","events_url":"https://api.github.com/users/Spongman/events{/privacy}","received_events_url":"https://api.github.com/users/Spongman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2019-01-15T20:25:41Z","updated_at":"2019-02-15T13:19:45Z","closed_at":null,"author_association":"NONE","body":"```c#\r\nvoid Foo<T>(T? foo) // error CS8627: A nullable type parameter must be known to be a value type or non-nullable reference type. Consider adding a 'class', 'struct', or type constraint.\r\n{\r\n}\r\n```\r\n\r\nbut there's no way to specify that `T` is non-nullable. i can specify `struct` or `class`, but i can't specify `either`.\r\n\r\nthe nullability check is forcing me to duplicate the definition of this method. like Java would :("},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/464048123","html_url":"https://github.com/dotnet/csharplang/issues/2146#issuecomment-464048123","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/2146","id":464048123,"node_id":"MDEyOklzc3VlQ29tbWVudDQ2NDA0ODEyMw==","user":{"login":"DavidArno","id":196899,"node_id":"MDQ6VXNlcjE5Njg5OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/196899?v=4","gravatar_id":"","url":"https://api.github.com/users/DavidArno","html_url":"https://github.com/DavidArno","followers_url":"https://api.github.com/users/DavidArno/followers","following_url":"https://api.github.com/users/DavidArno/following{/other_user}","gists_url":"https://api.github.com/users/DavidArno/gists{/gist_id}","starred_url":"https://api.github.com/users/DavidArno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavidArno/subscriptions","organizations_url":"https://api.github.com/users/DavidArno/orgs","repos_url":"https://api.github.com/users/DavidArno/repos","events_url":"https://api.github.com/users/DavidArno/events{/privacy}","received_events_url":"https://api.github.com/users/DavidArno/received_events","type":"User","site_admin":false},"created_at":"2019-02-15T13:19:45Z","updated_at":"2019-02-15T13:19:45Z","author_association":"NONE","body":"@333fred,\r\n\r\nA simple, complete scenario for you:\r\n```cs\r\npublic class Foo<T>\r\n{\r\n    public T? Prop { get; set; }\r\n}\r\n```\r\nThis gives a warning on `T?` as I can't constrain the class to work only with classes or structs. But if I remove the `?` it gives a warning that `Prop` is uninitialized, \r\n\r\nI simply want `Prop` to be allowed to be *defaultable*. The inability to do this makes NRTs incompatible with generics in any scenario where I simply want a default of `T`.\r\n\r\nI'm even wondering whether `T?` should mean \"defaultable\", not \"nullable\" in a generic context unless constrained to structs or classes."}}
{"actor":{"display_login":"DavidArno"}}