Skip to content

Give point position to synthetic class parent #5410

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 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ class Typer extends Namer
/** Ensure that first parent tree refers to a real class. */
def ensureFirstTreeIsClass(parents: List[Tree], pos: Position)(implicit ctx: Context): List[Tree] = parents match {
case p :: ps if p.tpe.classSymbol.isRealClass => parents
case _ => TypeTree(ensureFirstIsClass(parents.tpes, pos).head).withPos(pos) :: parents
case _ => TypeTree(ensureFirstIsClass(parents.tpes, pos).head).withPos(pos.focus) :: parents
}

/** If this is a real class, make sure its first parent is a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,34 @@ class DefinitionTest {
).definition(m3 to m4, List(m1 to m2))
}

@Test def definitionAnonClassTrait: Unit = {
code"""trait ${m1}Foo${m2} { val x = 0 }
class C {
def foo = new ${m3}Foo${m4} {}
}""".withSource
.definition(m1 to m2, List(m1 to m2))
.definition(m3 to m4, List(m1 to m2))
}

@Test def definitionAnonClassClass: Unit = {
code"""abstract class ${m1}Foo${m2} { val x = 0 }
class C {
def foo = new ${m3}Foo${m4} {}
}""".withSource
.definition(m1 to m2, List(m1 to m2))
.definition(m3 to m4, List(m1 to m2))
}

@Test def definitionAnonClassClassTrait: Unit = {
code"""abstract class ${m1}Foo${m2}
trait ${m3}Bar${m4}
class C {
def foo = new ${m5}Foo${m6} with ${m7}Bar${m8} {}
}""".withSource
.definition(m1 to m2, List(m1 to m2))
.definition(m3 to m4, List(m3 to m4))
.definition(m5 to m6, List(m1 to m2))
.definition(m7 to m8, List(m3 to m4))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ class ReferencesTest {
.references(m7 to m8, List(m7 to m8), withDecl = false)
}

@Test def anonClassTrait: Unit = {
code"""trait ${m1}Foo${m2}
object O {
val foo = new ${m3}Foo${m4} {}
}""".withSource
.references(m1 to m2, List(m1 to m2, m3 to m4), withDecl = true)
.references(m1 to m2, List(m3 to m4), withDecl = false)
.references(m3 to m4, List(m1 to m2, m3 to m4), withDecl = true)
.references(m3 to m4, List(m3 to m4), withDecl = false)
}

}