Skip to content

Add an error message class for sealed classes #3473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2017
Merged

Add an error message class for sealed classes #3473

merged 1 commit into from
Nov 22, 2017

Conversation

maseev
Copy link
Contributor

@maseev maseev commented Nov 14, 2017

This PR is related to #1589. Specifically, it adds a new error message class for the following case - Namer.scala:880.

Unfortunately, this PR doesn't have a unit test because I wasn't able to find a way to trigger this particular behavior. It seems to me that it's impossible at the moment to check some code which is separated into two different compilation units inside a unit test.

Maybe I'm simply missing something.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Added" instead of "Add")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

@maseev maseev changed the title Add an error message class for the case where it's impossible to exte… Add an error message class for sealed classes Nov 14, 2017
@maseev
Copy link
Contributor Author

maseev commented Nov 15, 2017

I'm just wondering, isn't this supposed to be

"Add" instead of "Added"

and not

"Added" instead of "Add"

in the 6th rule of commit messages?

According to this rule, you need to use the present simple tense and not the past tense for your commit messages. Otherwise, it would be an indicative mood which is all about reporting facts.

@allanrenucci
Copy link
Contributor

I'm just wondering, isn't this supposed to be "Add" instead of "Added"

Yes. Feel free to submit a PR. The message is in PullRequestService.scala:270


case class UnableToExtendSealedClass(pclazz: Symbol)(implicit ctx: Context) extends Message(UnableToExtendSealedClassID) {
val kind = "Syntax"
val msg = hl"cannot extend sealed $pclazz in different compilation unit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would refactor that and the extended message to only talk about files instead. It seams unnecessary to talk about compilation units here.

Here is what we have in the spec if that helps:

The sealed modifier applies to class definitions. A sealed class may not be directly inherited, except if the inheriting template is defined in the same source file as the inherited class. However, subclasses of a sealed class can be inherited anywhere.

|sealed class A
|class B extends A""".stripMargin

hl"""A ${"sealed"} keyword makes sure that all classes that extend a sealed class are
Copy link
Contributor

@OlivierBlanvillain OlivierBlanvillain Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I'm not convinced a super long description with correct/incorrect examples is helpful here. The top SO answer just goes straight to the point:

A sealed trait can be extended only in the same file as its declaration.

@maseev
Copy link
Contributor Author

maseev commented Nov 22, 2017

@OlivierBlanvillain PTAL

@OlivierBlanvillain
Copy link
Contributor

👍, thanks!

@maseev
Copy link
Contributor Author

maseev commented Nov 22, 2017

@OlivierBlanvillain, @allanrenucci sorry, I forgot to pull your changes first before doing a rebase. I applied the same changes you did to the message and explanation fields.

@OlivierBlanvillain
Copy link
Contributor

No worries, thank you for the PR!

@OlivierBlanvillain OlivierBlanvillain merged commit 9a0c822 into scala:master Nov 22, 2017
@maseev maseev deleted the iss1589-sealed-class-extension-violation branch November 22, 2017 14:13
@maseev maseev mentioned this pull request Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants