Skip to content

Commit 47aa75d

Browse files
committed
Fully compile primitive value classes
We used to drop compilation units for primitives after frontend, but this meant that a standard library compiled by dotty was not usable by dotty, because the primitive value classes were missing from the classpath: even though these classes are never loaded at runtime, they're unpickled at compile-time. Getting this to work required two changes: silence an error in refchecks (see comment) and turn off some computations in mixins that require cls.superClass to exist (primitives have no superclasses after erasure)
1 parent 2d9b3d1 commit 47aa75d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
270270
parents = impl.parents.map(p => TypeTree(p.tpe).withSpan(p.span)),
271271
body =
272272
if (cls.is(Trait)) traitDefs(impl.body)
273-
else {
273+
else if (!cls.isPrimitiveValueClass) {
274274
val mixInits = mixins.flatMap { mixin =>
275275
flatten(traitInits(mixin)) ::: superCallOpt(mixin) ::: setters(mixin) ::: mixinForwarders(mixin)
276276
}
277277
superCallOpt(superCls) ::: mixInits ::: impl.body
278-
})
278+
}
279+
else impl.body)
279280
}
280281
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class FrontEnd extends Phase {
8686
}
8787

8888
protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context): Boolean =
89-
unit.isJava || firstTopLevelDef(unit.tpdTree :: Nil).isPrimitiveValueClass
89+
unit.isJava
9090

9191
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
9292
val unitContexts = for (unit <- units) yield {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,14 @@ object RefChecks {
790790
case Nil =>
791791
ctx.error(OverridesNothing(member), member.sourcePos)
792792
case ms =>
793-
ctx.error(OverridesNothingButNameExists(member, ms), member.sourcePos)
793+
// getClass in primitive value classes is defined in the standard library as:
794+
// override def getClass(): Class[Int] = ???
795+
// However, it's not actually an override in Dotty because our Any#getClass
796+
// is polymorphic (see `Definitions#Any_getClass`), so since we can't change
797+
// the standard library, we need to drop the override flag without reporting
798+
// an error.
799+
if (!(member.name == nme.getClass_ && clazz.isPrimitiveValueClass))
800+
ctx.error(OverridesNothingButNameExists(member, ms), member.sourcePos)
794801
}
795802
member.resetFlag(Override)
796803
member.resetFlag(AbsOverride)

0 commit comments

Comments
 (0)