{"action":"created","issue":{"url":"https://api.github.com/repos/scala/bug/issues/9427","repository_url":"https://api.github.com/repos/scala/bug","labels_url":"https://api.github.com/repos/scala/bug/issues/9427/labels{/name}","comments_url":"https://api.github.com/repos/scala/bug/issues/9427/comments","events_url":"https://api.github.com/repos/scala/bug/issues/9427/events","html_url":"https://github.com/scala/bug/issues/9427","id":220110554,"node_id":"MDU6SXNzdWUyMjAxMTA1NTQ=","number":9427,"title":"Misleading error when \"implicitly\" cannot find value when used without type arg","user":{"login":"scabug","id":26753039,"node_id":"MDQ6VXNlcjI2NzUzMDM5","avatar_url":"https://avatars2.githubusercontent.com/u/26753039?v=4","gravatar_id":"","url":"https://api.github.com/users/scabug","html_url":"https://github.com/scabug","followers_url":"https://api.github.com/users/scabug/followers","following_url":"https://api.github.com/users/scabug/following{/other_user}","gists_url":"https://api.github.com/users/scabug/gists{/gist_id}","starred_url":"https://api.github.com/users/scabug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scabug/subscriptions","organizations_url":"https://api.github.com/users/scabug/orgs","repos_url":"https://api.github.com/users/scabug/repos","events_url":"https://api.github.com/users/scabug/events{/privacy}","received_events_url":"https://api.github.com/users/scabug/received_events","type":"User","site_admin":false},"labels":[{"id":578311321,"node_id":"MDU6TGFiZWw1NzgzMTEzMjE=","url":"https://api.github.com/repos/scala/bug/labels/minimized","name":"minimized","color":"c2e0c6","default":false},{"id":578311306,"node_id":"MDU6TGFiZWw1NzgzMTEzMDY=","url":"https://api.github.com/repos/scala/bug/labels/usability","name":"usability","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-08-03T13:21:10Z","updated_at":"2018-08-15T08:08:20Z","closed_at":null,"author_association":"NONE","body":"I have noticed that the `implicitly` method gives a rather strange error message if it is used without arguments and the implicit value cannot be found:\r\n\r\n```scala\r\nscala> class Foo\r\ndefined class Foo\r\n\r\nscala> val f: Foo = implicitly\r\n<console>:8: error: ambiguous implicit values:\r\n both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String]\r\n and method $conforms in object Predef of type [A]=> <:<[A,A]\r\n match expected type T\r\n       val f: Foo = implicitly\r\n                    ^\r\n```\r\n\r\nIf you pass it an explicit type param, it gives a much more sensible error:\r\n\r\n```scala\r\nscala> val f = implicitly[Foo]\r\n<console>:8: error: could not find implicit value for parameter e: Foo\r\n       val f = implicitly[Foo]\r\n                         ^\r\n```\r\n\r\nThis looks to me like a minor compiler bug. \r\nI like using \"implicitly\" without type args when the type can be inferred, e.g.\r\n\r\n```scala\r\nmyMethodWithLotsOfImplicits()(implicitly, implicitly, myExplicitOverride, implicitly, implicitly)\r\n```\r\n\r\nrather than, say:\r\n\r\n```scala\r\nmyMethodWithLotsOfImplicits()(implicitly[Something], implicitly[SomethingElse], myExplicitOverride, implicitly[YetAnother], implicitly[EvenMore])\r\n```\r\n\r\n... but this does give very misleading errors if one of the implicits can't be found, as shown above.\r\n\r\n## Minimised Repro case\r\n\r\n```scala\r\nscala> class Foo\r\ndefined class Foo\r\n\r\nscala> val f: Foo = implicitly\r\n```\r\n\r\n## Expected result:\r\n\r\n```scala\r\n<console>:8: error: could not find implicit value for parameter e: Foo\r\n       val f: Foo = implicitly\r\n                         ^\r\n```\r\n\r\n## Observed result:\r\n\r\n```scala\r\n<console>:8: error: ambiguous implicit values:\r\n both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String]\r\n and method $conforms in object Predef of type [A]=> <:<[A,A]\r\n match expected type T\r\n       val f: Foo = implicitly\r\n                    ^\r\n```\r\n\r\n## Related issues:\r\n\r\n#5801 looks similar, but that's marked as fixed in 2.10\r\n#8947 looks related, but marked fixed in 2.11.5\r\n"},"comment":{"url":"https://api.github.com/repos/scala/bug/issues/comments/413125221","html_url":"https://github.com/scala/bug/issues/9427#issuecomment-413125221","issue_url":"https://api.github.com/repos/scala/bug/issues/9427","id":413125221,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzEyNTIyMQ==","user":{"login":"jvican","id":2462974,"node_id":"MDQ6VXNlcjI0NjI5NzQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2462974?v=4","gravatar_id":"","url":"https://api.github.com/users/jvican","html_url":"https://github.com/jvican","followers_url":"https://api.github.com/users/jvican/followers","following_url":"https://api.github.com/users/jvican/following{/other_user}","gists_url":"https://api.github.com/users/jvican/gists{/gist_id}","starred_url":"https://api.github.com/users/jvican/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvican/subscriptions","organizations_url":"https://api.github.com/users/jvican/orgs","repos_url":"https://api.github.com/users/jvican/repos","events_url":"https://api.github.com/users/jvican/events{/privacy}","received_events_url":"https://api.github.com/users/jvican/received_events","type":"User","site_admin":false},"created_at":"2018-08-15T08:08:20Z","updated_at":"2018-08-15T08:08:20Z","author_association":"MEMBER","body":"I stumbled upon this today. Isn't there a way we can improve the error message here? It seems baffling to me that the compiler doesn't infer that `implicitly` means `implicitly[Int]` because of the the type ascription of its lhs. What am I missing?"}}
{"actor":{"display_login":"jvican"}}