{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/31865","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/31865/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/31865/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/31865/events","html_url":"https://github.com/dart-lang/sdk/issues/31865","id":287914952,"number":31865,"title":"Should List foos = <Foo>[] infer as List<Foo>?","user":{"login":"matanlurey","id":168174,"avatar_url":"https://avatars2.githubusercontent.com/u/168174?v=4","gravatar_id":"","url":"https://api.github.com/users/matanlurey","html_url":"https://github.com/matanlurey","followers_url":"https://api.github.com/users/matanlurey/followers","following_url":"https://api.github.com/users/matanlurey/following{/other_user}","gists_url":"https://api.github.com/users/matanlurey/gists{/gist_id}","starred_url":"https://api.github.com/users/matanlurey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matanlurey/subscriptions","organizations_url":"https://api.github.com/users/matanlurey/orgs","repos_url":"https://api.github.com/users/matanlurey/repos","events_url":"https://api.github.com/users/matanlurey/events{/privacy}","received_events_url":"https://api.github.com/users/matanlurey/received_events","type":"User","site_admin":false},"labels":[{"id":219928175,"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-language","name":"area-language","color":"c7def8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2018-01-11T20:32:09Z","updated_at":"2018-03-23T17:17:08Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"An internal customer ran into this pattern today:\r\n\r\n```dart\r\nclass X {\r\n  List foos = <Foo>[];\r\n}\r\n```\r\n\r\n... where it is (properly, at least according to the new spec) inferring as `List<dynamic>`, which in turn causes runtime errors when trying to assign `foos` to a true `List<Foo>`. I understand the intention behind this:\r\n\r\n```dart\r\nclass X {\r\n  // Don't infer me as List<int>\r\n  List<dynamic> anything = [1, 2, 3];\r\n}\r\n```\r\n\r\nThough the following is less clear than me.\r\n\r\nIn my head `anything` should just care about being a `List`, but its assigned value should be of `List<int>`, not `List<dynamic>`:\r\n\r\n```dart\r\nclass X {\r\n  // Don't infer me as List<int>... for some reason.\r\n  List<dynamic> anything = <int>[1, 2, 3];\r\n}\r\n```\r\n\r\nBut I really don't understand this one:\r\n\r\n```dart\r\nclass X {\r\n  // Inferred as List<dynamic>.\r\n  List ints = <int>[];\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/375738392","html_url":"https://github.com/dart-lang/sdk/issues/31865#issuecomment-375738392","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/31865","id":375738392,"user":{"login":"eernstg","id":9606994,"avatar_url":"https://avatars1.githubusercontent.com/u/9606994?v=4","gravatar_id":"","url":"https://api.github.com/users/eernstg","html_url":"https://github.com/eernstg","followers_url":"https://api.github.com/users/eernstg/followers","following_url":"https://api.github.com/users/eernstg/following{/other_user}","gists_url":"https://api.github.com/users/eernstg/gists{/gist_id}","starred_url":"https://api.github.com/users/eernstg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eernstg/subscriptions","organizations_url":"https://api.github.com/users/eernstg/orgs","repos_url":"https://api.github.com/users/eernstg/repos","events_url":"https://api.github.com/users/eernstg/events{/privacy}","received_events_url":"https://api.github.com/users/eernstg/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T17:17:08Z","updated_at":"2018-03-23T17:17:08Z","author_association":"MEMBER","body":"It is an error because it is not a downcast and not an upcast: `Set<int> --> LinkedHashSet<int> --> LinkedHashSet<dynamic>` goes down-then-up.\r\n\r\nOf course, if we add partial inference on type annotations then `LinkedHashSet` in the type annotation would mean `LinkedHashSet<int>`, and it would then be a plain downcast.\r\n\r\nAnd I still think it would be error-prone to allow partial type annotation inference with exactly the same syntax as instantiate-to-bound, but requesting it with `LinkedHashSet<> x = ...;` is much better."}}
{"actor":{"display_login":"eernstg"}}