Skip to content

Make the cached mirror methods invisible #13825

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

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ import transform.SymUtils._
val finalAddendum =
if addendum.nonEmpty then prefixEnumClause(addendum)
else closest match
case (d, sym) :: _ =>
case (d, sym) :: _ if sym.name != name =>
val siteName = site match
case site: NamedType => site.name.show
case site => i"$site"
Expand All @@ -357,7 +357,7 @@ import transform.SymUtils._
if sym.is(ModuleClass) then s"${sym.name.show}.type"
else sym.name.show
s" - did you mean $siteName.$showName?$enumClause"
case Nil => prefixEnumClause("")
case _ => prefixEnumClause("")

ex"$selected $name is not a member of ${site.widen}$finalAddendum"
}
Expand Down
16 changes: 9 additions & 7 deletions compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,10 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
declaredParents = oldClassInfo.declaredParents :+ parent)
clazz.copySymDenotation(info = newClassInfo).installAfter(thisPhase)
}
def addMethod(name: TermName, info: Type, cls: Symbol, body: (Symbol, Tree) => Context ?=> Tree): Unit = {
val meth = newSymbol(clazz, name, Synthetic | Method, info, coord = clazz.coord)
def addMethod(
name: TermName, info: Type, cls: Symbol,
body: (Symbol, Tree) => Context ?=> Tree): Unit = {
val meth = newSymbol(clazz, name, Synthetic | Method | Invisible, info, coord = clazz.coord)
if (!existingDef(meth, clazz).exists) {
meth.enteredAfter(thisPhase)
newBody = newBody :+
Expand All @@ -561,23 +563,23 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
if (existing.exists && !existing.is(Deferred)) existing
else {
val monoType =
newSymbol(clazz, tpnme.MirroredMonoType, Synthetic, TypeAlias(linked.reachableRawTypeRef), coord = clazz.coord)
newSymbol(clazz, tpnme.MirroredMonoType, Synthetic | Invisible, TypeAlias(linked.reachableRawTypeRef), coord = clazz.coord)
newBody = newBody :+ TypeDef(monoType).withSpan(ctx.owner.span.focus)
monoType.enteredAfter(thisPhase)
}
}
def makeSingletonMirror() =
addParent(defn.Mirror_SingletonClass.typeRef)
def makeProductMirror(cls: Symbol) = {

def makeProductMirror(cls: Symbol) =
addParent(defn.Mirror_ProductClass.typeRef)
addMethod(nme.fromProduct, MethodType(defn.ProductClass.typeRef :: Nil, monoType.typeRef), cls,
fromProductBody(_, _).ensureConforms(monoType.typeRef)) // t4758.scala or i3381.scala are examples where a cast is needed
}
def makeSumMirror(cls: Symbol) = {

def makeSumMirror(cls: Symbol) =
addParent(defn.Mirror_SumClass.typeRef)
addMethod(nme.ordinal, MethodType(monoType.typeRef :: Nil, defn.IntType), cls,
ordinalBody(_, _))
}

if (clazz.is(Module)) {
if (clazz.is(Case)) makeSingletonMirror()
Expand Down
16 changes: 16 additions & 0 deletions tests/neg/i13815.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

-- [E008] Not Found Error: tests/neg/i13815/Test_2.scala:1:14 ----------------------------------------------------------
1 |val box = Box.fromProduct((1, "a")) // error
| ^^^^^^^^^^^^^^^
| value fromProduct is not a member of object Box
-- [E007] Type Mismatch Error: tests/neg/i13815/Test_2.scala:2:46 ------------------------------------------------------
2 |val circleOrdinal = Shape.ordinal(Shape.Circle(r = 23)) // error
| ^^^^^^^^^^^^^^^^^^^^
| Found: Shape.Circle
Copy link
Member

Choose a reason for hiding this comment

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

this seems strange that making MirroredMonoType invisible now makes ordinal visible again

| Required: Shape.MirroredMonoType

longer explanation available when compiling with `-explain`
-- [E008] Not Found Error: tests/neg/i13815/Test_2.scala:3:13 ----------------------------------------------------------
3 |type T = Box.MirroredMonoType // error
| ^^^^^^^^^^^^^^^^^^^^
| type MirroredMonoType is not a member of object Box
1 change: 1 addition & 0 deletions tests/neg/i13815/Box_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case class Box(i: Int, s: String)
5 changes: 5 additions & 0 deletions tests/neg/i13815/Shape_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sealed trait Shape

object Shape:
case class Circle(r: Int) extends Shape
case class Square(width: Int) extends Shape
3 changes: 3 additions & 0 deletions tests/neg/i13815/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val box = Box.fromProduct((1, "a")) // error
val circleOrdinal = Shape.ordinal(Shape.Circle(r = 23)) // error
type T = Box.MirroredMonoType // error