Skip to content

Fix #7748: Don't allow case classes to be defined in universal traits #7772

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 3 commits into from
Dec 17, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Dec 15, 2019

No description provided.

@odersky odersky changed the title Fix #7748: Don't allow classes to be defined in universal traits Fix #7748: Don't allow case classes to be defined in universal traits Dec 15, 2019
@@ -1810,6 +1810,10 @@ class Typer extends Namer
// check value class constraints
checkDerivedValueClass(cls, body1)

val effectiveOwner = cls.owner.skipWeakOwner
if cls.is(CaseClass) && effectiveOwner.is(Trait) && !effectiveOwner.derivesFrom(defn.ObjectClass)
Copy link
Member

Choose a reason for hiding this comment

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

I think the previous version of this check was closer to being correct: defining a class or an object in a value class is disallowed, so we should similarly disallow them in universal traits. There was one build failure because the universal trait SeqOps in the standard library defines some private inner classes, which I think is fine as long as we infer that those are private[this] classes:

Suggested change
if cls.is(CaseClass) && effectiveOwner.is(Trait) && !effectiveOwner.derivesFrom(defn.ObjectClass)
if !cls.isRefinementClass && cls.isAllOf(PrivateLocal) && effectiveOwner.is(Trait) &&
!effectiveOwner.derivesFrom(defn.ObjectClass)
then

@smarter smarter merged commit b1eb3a8 into scala:master Dec 17, 2019
@smarter smarter deleted the fix-#7748 branch December 17, 2019 09:42
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.

2 participants