Skip to content

Commit 70ed5e4

Browse files
committed
experiment with supertypes
1 parent 2dbcf1f commit 70ed5e4

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
251251
private def companionPath(mirroredType: Type, cls: Symbol, pre: Type, span: Span)(using Context) =
252252
val clsType =
253253
// ok to assume healPrefix will succeed because `cls` and `pre` derive from the same type.
254+
// TODO: will fail, e.g. for value alias to case object - we still need to support `scala.package.None.type`
254255
TypeOps.healPrefix(mirroredType.mirrorCompanionRef, pre).toOption.get
255256
val ref = pathFor(clsType)
256257
assert(ref.symbol.is(Module) && (cls.is(ModuleClass) || (ref.symbol.companionClass == cls)))
@@ -330,6 +331,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
330331
mirrorRef.cast(mirrorType)
331332
end makeProductMirror
332333

334+
if pre == NoPrefix then
335+
report.error(i"$mirroredType is not a valid prod type, because it does not have a prefix")
336+
else
337+
report.warning(i"prod mirror with $mirroredType: pre $pre")
333338
mirroredType match
334339
case AndType(tp1, tp2) =>
335340
productMirror(tp1, formal, span).orElse(productMirror(tp2, formal, span))
@@ -359,6 +364,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
359364
val pre = TypeOps.extractPrefix(mirroredType) match
360365
case pre if pre.exists => pre
361366
case _ => return EmptyTree
367+
// if pre == NoPrefix then
368+
// report.error(i"$mirroredType is not a valid sum type, because it does not have a prefix")
369+
// else
370+
// report.warning(i"sum mirror with $mirroredType: pre $pre")
362371
val cls = mirroredType.classSymbol
363372
val useCompanion = cls.useCompanionAsSumMirror
364373

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.deriving.Mirror
2+
3+
@main def Test = {
4+
5+
class Foo {
6+
final val foo: Qux.type = Qux
7+
case object Qux
8+
}
9+
10+
class Bar extends Foo {
11+
summon[Mirror.Of[Bar.super.foo.type]] //
12+
}
13+
14+
}

tests/neg/anon-mirror-gen-this-b.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import scala.deriving.Mirror
88

99
object Foo {
1010

11-
sealed trait Item { thisItem =>
11+
sealed trait Item {
1212

13-
val mItem = summon[Mirror.Of[thisItem.type]] // error: Bar.A.type is not a subtype of thisItem.type
13+
val mItem = summon[Mirror.Of[Item.this.type]] // error: Bar.A.type is not a subtype of thisItem.type
1414

1515
}
1616
}

0 commit comments

Comments
 (0)