Skip to content

Commit 464b61c

Browse files
committed
Force definitions of quote methods when initializing Definitions
The methods have to be known when unpickling. Their type needs to be evaluated lazily, however, as otherwise `Expr` would be forced too early.
1 parent 7a1e933 commit 464b61c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,20 @@ class Definitions {
145145
}
146146

147147
private def enterPolyMethod(cls: ClassSymbol, name: TermName, typeParamCount: Int,
148-
resultTypeFn: PolyType => Type, flags: FlagSet = EmptyFlags) = {
148+
resultTypeFn: PolyType => Type, flags: FlagSet = EmptyFlags,
149+
useCompleter: Boolean = false) = {
149150
val tparamNames = PolyType.syntheticParamNames(typeParamCount)
150151
val tparamInfos = tparamNames map (_ => TypeBounds.empty)
151-
val ptype = PolyType(tparamNames)(_ => tparamInfos, resultTypeFn)
152-
enterMethod(cls, name, ptype, flags)
152+
def ptype = PolyType(tparamNames)(_ => tparamInfos, resultTypeFn)
153+
val info =
154+
if (useCompleter)
155+
new LazyType {
156+
def complete(denot: SymDenotation)(implicit ctx: Context): Unit = {
157+
denot.info = ptype
158+
}
159+
}
160+
else ptype
161+
enterMethod(cls, name, info, flags)
153162
}
154163

155164
private def enterT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
@@ -298,11 +307,13 @@ class Definitions {
298307

299308
/** Method representing a term quote */
300309
lazy val quoteMethod = enterPolyMethod(OpsPackageClass, nme.QUOTE, 1,
301-
pt => MethodType(pt.paramRefs(0) :: Nil, QuotedExprType.appliedTo(pt.paramRefs(0) :: Nil)))
310+
pt => MethodType(pt.paramRefs(0) :: Nil, QuotedExprType.appliedTo(pt.paramRefs(0) :: Nil)),
311+
useCompleter = true)
302312

303313
/** Method representing a type quote */
304314
lazy val typeQuoteMethod = enterPolyMethod(OpsPackageClass, nme.QUOTE, 1,
305-
pt => QuotedTypeType.appliedTo(pt.paramRefs(0) :: Nil))
315+
pt => QuotedTypeType.appliedTo(pt.paramRefs(0) :: Nil),
316+
useCompleter = true)
306317

307318
lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol(
308319
ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef))
@@ -1093,9 +1104,7 @@ class Definitions {
10931104

10941105
/** Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
10951106
lazy val syntheticCoreMethods =
1096-
AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod
1097-
//, quoteMethod, typeQuoteMethod // we omit these because they force Expr and Type too early
1098-
)
1107+
AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod, quoteMethod, typeQuoteMethod)
10991108

11001109
lazy val reservedScalaClassNames: Set[Name] = syntheticScalaClasses.map(_.name).toSet
11011110

0 commit comments

Comments
 (0)