{"action":"created","issue":{"url":"https://api.github.com/repos/lampepfl/dotty/issues/1589","repository_url":"https://api.github.com/repos/lampepfl/dotty","labels_url":"https://api.github.com/repos/lampepfl/dotty/issues/1589/labels{/name}","comments_url":"https://api.github.com/repos/lampepfl/dotty/issues/1589/comments","events_url":"https://api.github.com/repos/lampepfl/dotty/issues/1589/events","html_url":"https://github.com/lampepfl/dotty/issues/1589","id":182767932,"number":1589,"title":"Missing error messages","user":{"login":"felixmulder","id":1530049,"avatar_url":"https://avatars1.githubusercontent.com/u/1530049?v=4","gravatar_id":"","url":"https://api.github.com/users/felixmulder","html_url":"https://github.com/felixmulder","followers_url":"https://api.github.com/users/felixmulder/followers","following_url":"https://api.github.com/users/felixmulder/following{/other_user}","gists_url":"https://api.github.com/users/felixmulder/gists{/gist_id}","starred_url":"https://api.github.com/users/felixmulder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixmulder/subscriptions","organizations_url":"https://api.github.com/users/felixmulder/orgs","repos_url":"https://api.github.com/users/felixmulder/repos","events_url":"https://api.github.com/users/felixmulder/events{/privacy}","received_events_url":"https://api.github.com/users/felixmulder/received_events","type":"User","site_admin":false},"labels":[{"id":448935573,"url":"https://api.github.com/repos/lampepfl/dotty/labels/area:docs","name":"area:docs","color":"006b75","default":false},{"id":288602285,"url":"https://api.github.com/repos/lampepfl/dotty/labels/area:reporting","name":"area:reporting","color":"006b75","default":false},{"id":290472243,"url":"https://api.github.com/repos/lampepfl/dotty/labels/exp:novice","name":"exp:novice","color":"009800","default":false},{"id":706819707,"url":"https://api.github.com/repos/lampepfl/dotty/labels/Hacktoberfest","name":"Hacktoberfest","color":"d4c5f9","default":false},{"id":159371900,"url":"https://api.github.com/repos/lampepfl/dotty/labels/help%20wanted","name":"help wanted","color":"c2e0c6","default":true},{"id":21379539,"url":"https://api.github.com/repos/lampepfl/dotty/labels/itype:enhancement","name":"itype:enhancement","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":84,"created_at":"2016-10-13T11:48:09Z","updated_at":"2017-11-13T12:26:42Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"We have a multitude of errors that need to be ported to the [new scheme](http://scala-lang.org/blog/2016/10/14/dotty-errors.html) - you'll find these under \"Error Messages\" below. But first, a tutorial:\r\n# HOWTO on creating new messages\r\n\r\nOnce you've identified an error you want to replace, you should decide what semantic information is needed in the message - i.e. the position, perhaps a tree or some types. For this example we're going to be implementing the error message for the following error:\r\n\r\n``` scala\r\ncase class Foo // you're not allowed to have a case class without a single parameter list!\r\n```\r\n\r\nSo we create a file with this and compile it using `./bin/dotc test.scala`. This gives us the error message:\r\n\r\n```\r\ncase class Foo\r\n           ^\r\n           case class needs to have at least one parameter list\r\n```\r\n\r\nSo now we search the repository for \"case class needs to have\" - I do this with `git grep -n \"case class needs to have\"`.\r\n\r\nAnd now we find that in `src/dotty/tools/dotc/ast/Desugar.scala` we have the following line:\r\n\r\n``` scala\r\nctx.error(\"case class needs to have at least one parameter list\", cdef.pos)\r\n```\r\n\r\nCool - now we know what to replace. So next step is to add a `case class` to `src/dotty/tools/dotc/reporting/diagnostic/messages.scala`. The case class that we add should extend `Message`:\r\n\r\n``` scala\r\nabstract class Message(val errorId: Int) {\r\n  /** The `msg` contains the diagnostic message e.g:\r\n    *\r\n    * > expected: String\r\n    * > found:    Int\r\n    *\r\n    * This message wil be placed underneath the position given by the enclosing\r\n    * `MessageContainer`\r\n    */\r\n  def msg: String\r\n\r\n  /** The kind of the error message is something like \"Syntax\" or \"Type\r\n    * Mismatch\"\r\n    */\r\n  def kind: String\r\n\r\n  /** The explanation should provide a detailed description of why the error\r\n    * occurred and use examples from the user's own code to illustrate how to\r\n    * avoid these errors.\r\n    */\r\n  def explanation: String\r\n  ...\r\n}\r\n```\r\n\r\nNow we name our case class something useful and give it a unique `errorId`:\r\n\r\n``` scala\r\ncase class CaseClassMissingParamList() extends Message(4)\r\n```\r\n\r\nSince we can see that the call to `ctx.error` took the position of a `cdef: TypeDef`, we could perhaps use this in the constructor of our `Message`?\r\n\r\n``` scala\r\ncase class CaseClassMissingParamList(cdef: untpd.TypeDef) extends Message(4)\r\n```\r\n\r\nIt might also be that we're going to be manipulating `cdef` tree, as such we should pass a `Context` to get all the implicit operations:\r\n\r\n``` scala\r\ncase class CaseClassMissingParamList(cdef: untpd.TypeDef)(implicit ctx: Context)\r\nextends Message(4)\r\n```\r\n\r\nAlright! Now we can start adding things to our `Messsage`:\r\n\r\n``` scala\r\ncase class CaseClassMissingParamList(cdef: untpd.TypeDef)(implicit ctx: Context)\r\nextends Message(4) {\r\n  val kind = \"Syntax\" // this will be shown as a delimiter: \"-- [E004] Syntax X -------\"\r\n\r\n  // we can use the \"hl\" interpolator to give syntax highlighting to our message:\r\n  val msg =\r\n    hl\"\"\"|A ${\"case class\"} must have at least one parameter list\"\"\"\r\n\r\n  // not everything that is interpolated will be highlighted, for instance you can use\r\n  // colors like: Red(\"must\") - this will get the red color.\r\n  val explanation =\r\n    hl\"\"\"|${cdef.name} ${Red(\"must\")} have at least one parameter list, if you would rather\r\n         |have a singleton representation of ${cdef.name}, use a \"${\"case object\"}\".\r\n         |Or, add an explicit `()' as a parameter list to ${cdef.name}.\"\"\".stripMargin\r\n}\r\n```\r\n\r\n# Stable Identifier #\r\nSo far, we've simplified the above cases a smidge, the error messages themselves actually don't extend `Message` by passing an integer. They should actually create an entry into the java enum defined in [ErrorMessageID.java](https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java). This will enable us to have stable identifiers which helps tooling between the different compilers.\r\n\r\nNow you replace the call to `ctx.error(String)` with `ctx.error(CaseClassMissingParamList(cdef))` - and you're done with the implementation!\r\n\r\n# Tests #\r\nTo test your solution, add a test to [ErrorMessagesTests.scala](https://github.com/lampepfl/dotty/blob/master/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala). An example for `TypeMismatch` is provided and documented.\r\n\r\n## Online documentation ##\r\nWe really want to have online documentation providing more detailed information on what went wrong. Currently the idea is to create markdown pages in the `docs/docs` folder. Any contribution here would be greatly appreciated!\r\n\r\n# Things to keep in mind #\r\n- You're creating a semantic object - this object will either be the output of the terminal or it could be used in an IDE, so make sure to include the relevant things. Typically: `Types`, `Position`, `Tree`\r\n- Name your error something easy to understand!\r\n- If you think your error doesn't need an explanation - that's fine - just put `val explanation = \"\"`\r\n- If you find yourself not being able to manipulate trees - do you have the implicit context?\r\n- \"HALP!\" - please post in our gitter channel: https://gitter.im/lampepfl/dotty or comment on this issue :smiley: \r\n# Missing Messages\r\n\r\nPlease comment below saying which messages you'd like to tackle.\r\n\r\n\r\nAvailable\r\n----------\r\n- Applications.scala:95\r\n- Applications.scala:972\r\n- Checking.scala:49\r\n- Checking.scala:526\r\n- Checking.scala:533\r\n- Checking.scala:539\r\n- Checking.scala:551\r\n- Checking.scala:555\r\n- Checking.scala:565\r\n- Checking.scala:576\r\n- Checking.scala:583\r\n- Checking.scala:602\r\n- Checking.scala:622\r\n- Checking.scala:628\r\n- Checking.scala:646\r\n- Checking.scala:648\r\n- Checking.scala:692\r\n- Checking.scala:702\r\n- Checking.scala:716\r\n- Docstrings.scala:30\r\n- Namer.scala:222\r\n- Namer.scala:258\r\n- Namer.scala:872\r\n- Namer.scala:880\r\n- Namer.scala:1081\r\n- Namer.scala:1105\r\n- Parsers.scala:2266\r\n- Parsers.scala:2438\r\n- Parsers.scala:2456\r\n- PatternMatcher.scala:911\r\n- RefChecks.scala:609\r\n- RefChecks.scala:694\r\n- RefChecks.scala:698\r\n- RefChecks.scala:874\r\n- SymDenotations.scala:1964\r\n- TypeAssigner.scala:34\r\n- TypeAssigner.scala:208\r\n- TypeAssigner.scala:233 \r\n- TypeAssigner.scala:299\r\n- TypeAssigner.scala:314\r\n- TypeAssigner.scala:356\r\n- TypeAssigner.scala:358\r\n- TypeAssigner.scala:416\r\n- Typer.scala:174\r\n- Typer.scala:196\r\n- Typer.scala:355\r\n- Typer.scala:411\r\n- Typer.scala:866\r\n- Typer.scala:1109\r\n- Typer.scala:1519\r\n- Typer.scala:1572\r\n- Typer.scala:1731\r\n- Typer.scala:1924\r\n- Typer.scala:2015\r\n\r\n\r\nContributors\r\n-------------\r\n- @abeln\r\n- @AndrewZurn\r\n- @b-studios\r\n- @gvolpe\r\n- @insdami\r\n- @jarrodj \r\n- @johnregan \r\n- @jyotman94\r\n- @ljdelight\r\n- @lorandszakacs\r\n- @m-sp\r\n- @mads-hartmann \r\n- @maseev \r\n- @mikla \r\n- @msosnicki\r\n- @rubenpieters\r\n- @sebastianharko\r\n- @ShaneDelmore \r\n- @thiagoandrade6"},"comment":{"url":"https://api.github.com/repos/lampepfl/dotty/issues/comments/343904037","html_url":"https://github.com/lampepfl/dotty/issues/1589#issuecomment-343904037","issue_url":"https://api.github.com/repos/lampepfl/dotty/issues/1589","id":343904037,"user":{"login":"maseev","id":3434800,"avatar_url":"https://avatars0.githubusercontent.com/u/3434800?v=4","gravatar_id":"","url":"https://api.github.com/users/maseev","html_url":"https://github.com/maseev","followers_url":"https://api.github.com/users/maseev/followers","following_url":"https://api.github.com/users/maseev/following{/other_user}","gists_url":"https://api.github.com/users/maseev/gists{/gist_id}","starred_url":"https://api.github.com/users/maseev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maseev/subscriptions","organizations_url":"https://api.github.com/users/maseev/orgs","repos_url":"https://api.github.com/users/maseev/repos","events_url":"https://api.github.com/users/maseev/events{/privacy}","received_events_url":"https://api.github.com/users/maseev/received_events","type":"User","site_admin":false},"created_at":"2017-11-13T12:26:42Z","updated_at":"2017-11-13T12:26:42Z","author_association":"CONTRIBUTOR","body":"I'll take this one - `Checking.scala:551`"}}
{"actor":{"display_login":"maseev"}}