Skip to content

Fix compiler crash for repeated Enums #4530

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 10 commits into from
May 28, 2018

Conversation

snadorp
Copy link

@snadorp snadorp commented May 15, 2018

Fix: #4470

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 ("Add" instead of "Added")
  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! ☀️

@snadorp
Copy link
Author

snadorp commented May 15, 2018

CLA signed.

@snadorp snadorp force-pushed the fix/repeatedEnum branch from 8382d22 to 89d51d8 Compare May 15, 2018 10:18
@OlivierBlanvillain
Copy link
Contributor

@smarter wdyt?

@snadorp snadorp force-pushed the fix/repeatedEnum branch from 89d51d8 to 6891d2f Compare May 15, 2018 10:22
@smarter
Copy link
Member

smarter commented May 15, 2018

  • Doing the check in expandSimpleEnumCase is too late since it doesn't cover enum cases with parents:
enum Maybe[T] {
  case Foo extends Maybe[Int]
}

enum Maybe[T] {
  case Foo extends Maybe[Int]
}
  • we probably should add an assert(ctx.reporter.errorsReported) since we should never get to this case unless the "class has already been compiled" error has been reported.

@snadorp
Copy link
Author

snadorp commented May 15, 2018

@smarter Sadly assert(ctx.reporter.errorsReported) does not work.
I've added your example as test case and fixed the crash.

val valuesDef = enumDefDef("enumValues", "values")
List(privateValuesDef, valueOfDef, withNameDef, valuesDef)

if (enumClass.exists) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of duplicating the check, you should be able to have only one check done earlier, in expandEnumModule

Copy link
Author

Choose a reason for hiding this comment

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

You are right, I'll look into it.

@snadorp snadorp force-pushed the fix/repeatedEnum branch from abab86c to 4f36b2b Compare May 15, 2018 12:20
Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

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

Here is another test case that crashes on master:

object DuplicatedEnum {
  enum Maybe[+T] {
    case Some(x: T)
  }

  enum Maybe[+T] {
    case Some(x: T)
  }
}

@@ -0,0 +1,10 @@
object RepeatedEnum {
Copy link
Contributor

Choose a reason for hiding this comment

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

Our convention is to name our regression test files like i4470.scala. If you have mutiple test cases: i4470a.scala, i4470b.scala

Copy link
Author

Choose a reason for hiding this comment

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

Alrighty, will rename the files thanks for the hint.

@snadorp
Copy link
Author

snadorp commented May 15, 2018

@allanrenucci will look into it.

@snadorp
Copy link
Author

snadorp commented May 15, 2018

From my perspective there's no simple way of getting rid of the 2 ifs in expandEnumModule and expandSimpleEnumCase as they are both called from Desugar on different occasions.
Expanding only in cases when there's no compiler error breaks a couple of unit test and is therefore not the wanted behaviour.
Any other ideas?

@allanrenucci allanrenucci merged commit c8e18a3 into scala:master May 28, 2018
@allanrenucci
Copy link
Contributor

Thanks @snadorp 🎉

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