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

Also consider @targetName when checking private overrides #18361

Merged
merged 1 commit into from
Aug 9, 2023
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/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ object SymDenotations {
*
* site: Subtype of both inClass and C
*/
final def matchingDecl(inClass: Symbol, site: Type)(using Context): Symbol = {
final def matchingDecl(inClass: Symbol, site: Type, name: Name = this.name)(using Context): Symbol = {
var denot = inClass.info.nonPrivateDecl(name)
if (denot.isTerm) // types of the same name always match
denot = denot.matchingDenotation(site, site.memberInfo(symbol), symbol.targetName)
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,9 @@ object RefChecks {
then
val cls = sym.owner.asClass
for bc <- cls.baseClasses.tail do
val other = sym.matchingDecl(bc, cls.thisType)
var other = sym.matchingDecl(bc, cls.thisType)
if !other.exists && sym.targetName != sym.name then
other = sym.matchingDecl(bc, cls.thisType, sym.targetName)
if other.exists then
report.error(em"private $sym cannot override ${other.showLocated}", sym.srcPos)
end checkNoPrivateOverrides
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/i18244.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.annotation.*

class A:
def foo: Int = 1
class B extends A:
@targetName("foo") private[this] def bla: Int = 2 // error
class C extends A:
@targetName("foo") private def bla: Int = 2 // error

@main def Test =
val b = new B
println(b.foo)