{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/31665","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/31665/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/31665/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/31665/events","html_url":"https://github.com/dart-lang/sdk/issues/31665","id":282543757,"number":31665,"title":"Need clarification about instantiation of local and top level functions","user":{"login":"stereotype441","id":306375,"avatar_url":"https://avatars2.githubusercontent.com/u/306375?v=4","gravatar_id":"","url":"https://api.github.com/users/stereotype441","html_url":"https://github.com/stereotype441","followers_url":"https://api.github.com/users/stereotype441/followers","following_url":"https://api.github.com/users/stereotype441/following{/other_user}","gists_url":"https://api.github.com/users/stereotype441/gists{/gist_id}","starred_url":"https://api.github.com/users/stereotype441/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stereotype441/subscriptions","organizations_url":"https://api.github.com/users/stereotype441/orgs","repos_url":"https://api.github.com/users/stereotype441/repos","events_url":"https://api.github.com/users/stereotype441/events{/privacy}","received_events_url":"https://api.github.com/users/stereotype441/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":21,"created_at":"2017-12-15T20:48:14Z","updated_at":"2018-03-21T09:43:28Z","closed_at":null,"author_association":"MEMBER","body":"All of the discussion in the language spec about closurization refers specifically to closurizing instance methods.  However, it appears that static methods, top level functions, and local functions are also allowed to be closurized, as illustrated by the test below, which passes on the VM, dart2js, and DDC:\r\n\r\n```dart\r\nimport 'package:expect/expect.dart';\r\nint f(int i) => i + 1;\r\nclass C {\r\n  static int f(int i) => i + 2;\r\n  int g(int i) => i + 3;\r\n}\r\nmain() {\r\n  int h(int i) => i + 4;\r\n  int Function(int) func;\r\n  func = f;\r\n  Expect.equals(func(10), 11);\r\n  func = C.f;\r\n  Expect.equals(func(10), 12);\r\n  func = new C().g;\r\n  Expect.equals(func(10), 13);\r\n  func = h;\r\n  Expect.equals(func(10), 14);\r\n}\r\n```\r\n\r\nIn particular, the closurization of local functions seems to contradict the commentary text that says:\r\n\r\n> Closures derived from members via closurization are colloquially known as tear-offs.\r\n\r\nThe question arose in the code review of https://dart-review.googlesource.com/c/sdk/+/29744, which adds the ability for the front end to implicitly instantiate generic parameters when performing closurization of a method/function, e.g.:\r\n\r\n```dart\r\nimport 'package:expect/expect.dart';\r\nT f<T extends num>(T i) => i + 1;\r\nclass C {\r\n  static T f<T extends num>(T i) => i + 2;\r\n  T g<T extends num>(T i) => i + 3;\r\n}\r\nmain() {\r\n  T h<T extends num>(T i) => i + 4;\r\n  int Function(int) func;\r\n  func = f;\r\n  Expect.equals(func(10), 11);\r\n  func = C.f;\r\n  Expect.equals(func(10), 12);\r\n  func = new C().g;\r\n  Expect.equals(func(10), 13);\r\n  func = h;\r\n  Expect.equals(func(10), 14);\r\n}\r\n``` \r\n\r\nIt would be helpful to have clarification on the following questions:\r\n- Is it intended that closurization be possible with instance methods, static methods, top level functions, and local functions?  Or should some of the code in the first example lead to an error?\r\n- Is it intended that implicit instantiation of closurizations be possible with instance methods, static methods, top level functions, and local functions?  Or should some of the code in the second example lead to an error?\r\n- Is \"tear-off\" synonymous with \"closurization\" or does \"tear-off\" only refer to cases where a class member has been closurized?\r\n\r\nCC: @leafpetersen @lrhn @kmillikin "},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/374880846","html_url":"https://github.com/dart-lang/sdk/issues/31665#issuecomment-374880846","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/31665","id":374880846,"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-21T09:43:28Z","updated_at":"2018-03-21T09:43:28Z","author_association":"MEMBER","body":"Note that I've modified the [feature spec of generic function instantiation](https://dart-review.googlesource.com/c/sdk/+/47043) to specify that local functions are supported as well. Some reasons for that change are given in a comment on patch set 15."}}
{"actor":{"display_login":"eernstg"}}