{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/27755","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/27755/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/27755/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/27755/events","html_url":"https://github.com/dart-lang/sdk/issues/27755","id":187218994,"number":27755,"title":"Sealing or watching List objects, or copy-on-write List objects","user":{"login":"Hixie","id":551196,"avatar_url":"https://avatars1.githubusercontent.com/u/551196?v=3","gravatar_id":"","url":"https://api.github.com/users/Hixie","html_url":"https://github.com/Hixie","followers_url":"https://api.github.com/users/Hixie/followers","following_url":"https://api.github.com/users/Hixie/following{/other_user}","gists_url":"https://api.github.com/users/Hixie/gists{/gist_id}","starred_url":"https://api.github.com/users/Hixie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hixie/subscriptions","organizations_url":"https://api.github.com/users/Hixie/orgs","repos_url":"https://api.github.com/users/Hixie/repos","events_url":"https://api.github.com/users/Hixie/events{/privacy}","received_events_url":"https://api.github.com/users/Hixie/received_events","type":"User","site_admin":false},"labels":[{"id":219928165,"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-vm","name":"area-vm","color":"c7def8","default":false},{"id":334529267,"url":"https://api.github.com/repos/dart-lang/sdk/labels/Type:%20enhancement","name":"Type: enhancement","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":23,"created_at":"2016-11-03T23:41:57Z","updated_at":"2017-06-15T21:27:58Z","closed_at":null,"body":"In Flutter, we pass lists around but it is a convention that once you have passed a list to an object, you no longer \"own\" the list and are not allowed to modify it.\r\n\r\nUnfortunately, nothing in the language, API, or tooling actually support this, and so it's very easy for our customers to think they are keeping ownership of the list and for them to then run into trouble when either the changes have no effect, or the changes unexpectedly have an effect, depending on what they were trying to do.\r\n\r\n----\r\nPossible ways we could address this:\r\n* having a way to \"seal\" a List object and thus prevent people who have references to it from ever modifying the list again.\r\n* having a way to be notified when a List object created from a literal is changed, so that we could then throw with a message that says \"you can't modify the list\"\r\n* have a way to very cheaply \"copy\" a List object created from a literal, using techniques such as \"copy on write\", so that we can say that later modifying the list is fine but doesn't affect the widgets that used the original copy. (Ideally such a solution would be compatible with passing const lists to const constructors but having those same constructors usable with `new` and getting this copy-on-write behaviour.)"},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/308870767","html_url":"https://github.com/dart-lang/sdk/issues/27755#issuecomment-308870767","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/27755","id":308870767,"user":{"login":"matanlurey","id":168174,"avatar_url":"https://avatars1.githubusercontent.com/u/168174?v=3","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},"created_at":"2017-06-15T21:27:58Z","updated_at":"2017-06-15T21:27:58Z","body":"```dart\r\nfinal bool _assertionsEnabled = (){\r\n  var enabled = false;\r\n  assert(enabled = true);\r\n  return enabled;\r\n})();\r\n\r\nList<T> debugSeal<T>(List<T> list) {\r\n  if (_assertionsEnabled) {\r\n    // Could replace with 'FlutterUnmodifiableList' if you want a custom message.\r\n    return new List<T>.unmodifiable(list);\r\n  }\r\n  return list;\r\n}\r\n\r\n```"}}
{"actor":{"display_login":"matanlurey"}}