Skip to content

Commit e3874b1

Browse files
committed
Map underlying -> superType in transformations
1 parent d65d177 commit e3874b1

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ object ExplicitOuter {
317317
case _ =>
318318
// Need to be careful to dealias before erasure, otherwise we lose prefixes.
319319
atPhaseNoLater(erasurePhase)(outerPrefix(tpe.underlying))
320+
// underlying is fine here and below since we are calling this after erasure.
321+
// However, there is some weird stuff going on with parboiled2 where an
322+
// AppliedType with a type alias as constructor is fed to outerPrefix.
323+
// For some other unknown reason this works with underlying but not with superType.
324+
// I was not able to minimize the problem and parboiled2 spits out way too much
325+
// macro generated code to be able to pinpoint the root problem.
320326
}
321327
case tpe: TypeProxy =>
322328
outerPrefix(tpe.underlying)

compiler/src/dotty/tools/dotc/transform/TypeUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ object TypeUtils {
104104
case self @ TypeRef(prefix, _) if self.symbol.isClass =>
105105
prefix.select(self.symbol.companionModule).asInstanceOf[TermRef]
106106
case self: TypeProxy =>
107-
self.underlying.mirrorCompanionRef
107+
self.superType.mirrorCompanionRef
108108
}
109109

110110
/** Is this type a methodic type that takes implicit parameters (both old and new) at some point? */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ trait Deriving {
286286
case tp @ TypeRef(prefix, _) if tp.symbol.isClass =>
287287
prefix.select(tp.symbol.companionModule).asInstanceOf[TermRef]
288288
case tp: TypeProxy =>
289-
companionRef(tp.underlying)
289+
companionRef(tp.superType)
290290
}
291291
val resultType = instantiated(sym.info)
292292
val companion = companionRef(resultType)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class ImplicitSearchError(
257257
++ ErrorReporting.matchReductionAddendum(pt)
258258
}
259259

260-
private def formatMsg(shortForm: String)(headline: String = shortForm) = arg match
260+
private def formatMsg(shortForm: String)(headline: String = shortForm) = arg match
261261
case arg: Trees.SearchFailureIdent[?] =>
262262
arg.tpe match
263263
case _: NoMatchingImplicits => headline
@@ -387,7 +387,7 @@ class ImplicitSearchError(
387387
.map(userDefinedImplicitNotFoundTypeMessage)
388388
.find(_.isDefined).flatten
389389
case tp: TypeProxy =>
390-
recur(tp.underlying)
390+
recur(tp.superType)
391391
case tp: AndType =>
392392
recur(tp.tp1).orElse(recur(tp.tp2))
393393
case _ =>

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,16 +549,16 @@ object Implicits:
549549
override def msg(using Context) = _msg
550550
def explanation(using Context) = msg.toString
551551

552-
/** A search failure type for failed synthesis of terms for special types */
552+
/** A search failure type for failed synthesis of terms for special types */
553553
class SynthesisFailure(reasons: List[String], val expectedType: Type) extends SearchFailureType:
554554
def argument = EmptyTree
555555

556-
private def formatReasons =
557-
if reasons.length > 1 then
558-
reasons.mkString("\n\t* ", "\n\t* ", "")
559-
else
556+
private def formatReasons =
557+
if reasons.length > 1 then
558+
reasons.mkString("\n\t* ", "\n\t* ", "")
559+
else
560560
reasons.mkString
561-
561+
562562
def explanation(using Context) = em"Failed to synthesize an instance of type ${clarify(expectedType)}: ${formatReasons}"
563563

564564
end Implicits
@@ -763,7 +763,7 @@ trait ImplicitRunInfo:
763763
WildcardType
764764
else
765765
seen += t
766-
t.underlying match
766+
t.superType match
767767
case TypeBounds(lo, hi) =>
768768
if lo.isBottomTypeAfterErasure then apply(hi)
769769
else AndType.make(apply(lo), apply(hi))
@@ -871,7 +871,7 @@ trait Implicits:
871871
SearchFailure(new SynthesisFailure(errors, formal), span).tree
872872
else
873873
tree.orElse(failed)
874-
874+
875875

876876
/** Search an implicit argument and report error if not found */
877877
def implicitArgTree(formal: Type, span: Span)(using Context): Tree = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
365365
// avoid type aliases for tuples
366366
Right(MirrorSource.GenericTuple(types))
367367
case _ => reduce(tp.underlying)
368-
case _ => reduce(tp.underlying)
368+
case _ => reduce(tp.superType)
369369
case tp @ AndType(l, r) =>
370370
for
371371
lsrc <- reduce(l)

tests/new/test.scala

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
object Test:
1+
abstract class TestParserSpec:
2+
type TestParser1[T] = TestParser[T *: EmptyTuple, T]
3+
4+
def foo = 1
5+
6+
abstract class TestParser[L <: Tuple, Out] {
7+
def baz = foo
8+
}
9+
10+
def Tests(actions: => Unit) = ()
11+
12+
object ActionSpec extends TestParserSpec:
13+
val tests = Tests {
14+
val x = new TestParser1[String] {
15+
//def bar = foo
16+
}
17+
}
18+
19+
20+
21+
22+
223

3-
def test = ???

0 commit comments

Comments
 (0)