Skip to content

Fully compile primitive value classes #7447

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

Merged
merged 1 commit into from
Oct 26, 2019
Merged
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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
parents = impl.parents.map(p => TypeTree(p.tpe).withSpan(p.span)),
body =
if (cls.is(Trait)) traitDefs(impl.body)
else {
else if (!cls.isPrimitiveValueClass) {
val mixInits = mixins.flatMap { mixin =>
flatten(traitInits(mixin)) ::: superCallOpt(mixin) ::: setters(mixin) ::: mixinForwarders(mixin)
}
superCallOpt(superCls) ::: mixInits ::: impl.body
})
}
else impl.body)
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/FrontEnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class FrontEnd extends Phase {
}

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

override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
val unitContexts = for (unit <- units) yield {
Expand Down
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,14 @@ object RefChecks {
case Nil =>
ctx.error(OverridesNothing(member), member.sourcePos)
case ms =>
ctx.error(OverridesNothingButNameExists(member, ms), member.sourcePos)
// getClass in primitive value classes is defined in the standard library as:
// override def getClass(): Class[Int] = ???
// However, it's not actually an override in Dotty because our Any#getClass
// is polymorphic (see `Definitions#Any_getClass`), so since we can't change
// the standard library, we need to drop the override flag without reporting
// an error.
if (!(member.name == nme.getClass_ && clazz.isPrimitiveValueClass))
ctx.error(OverridesNothingButNameExists(member, ms), member.sourcePos)
}
member.resetFlag(Override)
member.resetFlag(AbsOverride)
Expand Down