Skip to content
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

Add error message when trait parameter prefixes are used for its parent #7393

Merged
merged 1 commit into from
Oct 13, 2019

Conversation

harpresing
Copy link
Contributor

@harpresing harpresing commented Oct 8, 2019

Tackling lampepfl#1589. More specifically, added an explanation for the compiler error when a trait with parameters is extended from a parent that is accessed via any of the parameters of the same trait.

For example:

class Outer {
  trait Inner
  trait Test(val outer: Outer) extends outer.Inner // error
}

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! ❤️

Have an awesome day! ☀️

@harpresing harpresing force-pushed the master branch 2 times, most recently from 16766af to 9e22e85 Compare October 11, 2019 11:30
@@ -116,7 +116,7 @@ object RefChecks {
case TypeRef(ref: TermRef, _) =>
val paramRefs = ref.namedPartsWith(ntp => ntp.symbol.enclosingClass == cls)
if (paramRefs.nonEmpty)
ctx.error("trait parameters cannot be used as parent prefixes", parent.sourcePos)
ctx.error(TraitParameterUsedAsParentPrefix(paramRefs.tail.head), parent.sourcePos)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens here if paramRefs has only one element? What is in paramRefs.head?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

paramRefs.head contains the enclosing class/trait and the second element in paramRefs is the trait which has the reference error. Given the nature of the error, paramRefs should always have 2 elements if it's nonEmpty.

Nonetheless, paramRefs.tail.head.symbol is the same as the parameter cls, so it's probably safer to use that instead. I'll make that change!

@nicolasstucki nicolasstucki merged commit 0f7a85b into scala:master Oct 13, 2019
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.

4 participants