Skip to content

Commit 8529f59

Browse files
committed
Merge pull request #919 from dotty-staging/stdlib-option
Fixes to make scala.Option compile
2 parents b1cb0af + f2187f3 commit 8529f59

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ object desugar {
236236
// prefixed by type or val). `tparams` and `vparamss` are the type parameters that
237237
// go in `constr`, the constructor after desugaring.
238238

239+
val isCaseClass = mods.is(Case) && !mods.is(Module)
240+
239241
val constrTparams = constr1.tparams map toDefParam
240242
val constrVparamss =
241243
if (constr1.vparamss.isEmpty) { // ensure parameter list is non-empty
242-
if (mods is Case)
244+
if (isCaseClass)
243245
ctx.error("case class needs to have at least one parameter list", cdef.pos)
244246
ListOfNil
245247
}
@@ -287,7 +289,7 @@ object desugar {
287289
// neg/t1843-variances.scala for a test case. The test would give
288290
// two errors without @uncheckedVariance, one of them spurious.
289291
val caseClassMeths =
290-
if (mods is Case) {
292+
if (isCaseClass) {
291293
def syntheticProperty(name: TermName, rhs: Tree) =
292294
DefDef(name, Nil, Nil, TypeTree(), rhs).withMods(synthetic)
293295
val isDefinedMeth = syntheticProperty(nme.isDefined, Literal(Constant(true)))
@@ -326,9 +328,9 @@ object desugar {
326328
if (targs.isEmpty) tycon else AppliedTypeTree(tycon, targs)
327329
}
328330

329-
// Case classes get a ProductN parent
331+
// Case classes and case objects get a ProductN parent
330332
var parents1 = parents
331-
if ((mods is Case) && arity <= Definitions.MaxTupleArity)
333+
if (mods.is(Case) && arity <= Definitions.MaxTupleArity)
332334
parents1 = parents1 :+ productConstr(arity)
333335

334336
// The thicket which is the desugared version of the companion object
@@ -350,7 +352,7 @@ object desugar {
350352
// (T11, ..., T1N) => ... => (TM1, ..., TMN) => C
351353
// For all other classes, the parent is AnyRef.
352354
val companions =
353-
if (mods is Case) {
355+
if (isCaseClass) {
354356
val parent =
355357
if (constrTparams.nonEmpty ||
356358
constrVparamss.length > 1 ||
@@ -386,7 +388,7 @@ object desugar {
386388
ctx.error("implicit classes may not be toplevel", cdef.pos)
387389
Nil
388390
}
389-
else if (mods is Case) {
391+
else if (isCaseClass) {
390392
ctx.error("implicit classes may not be case classes", cdef.pos)
391393
Nil
392394
}
@@ -407,7 +409,7 @@ object desugar {
407409
val originalTparams = constr1.tparams.toIterator
408410
val originalVparams = constr1.vparamss.toIterator.flatten
409411
val tparamAccessors = derivedTparams.map(_.withMods(originalTparams.next.mods))
410-
val caseAccessor = if (mods is Case) CaseAccessor else EmptyFlags
412+
val caseAccessor = if (isCaseClass) CaseAccessor else EmptyFlags
411413
val vparamAccessors = derivedVparamss.flatten.map(_.withMods(originalVparams.next.mods | caseAccessor))
412414
cpy.TypeDef(cdef)(
413415
rhs = cpy.Template(impl)(constr, parents1, self1,
@@ -453,7 +455,7 @@ object desugar {
453455
.withPos(tmpl.self.pos orElse tmpl.pos.startPos)
454456
val clsTmpl = cpy.Template(tmpl)(self = clsSelf, body = tmpl.body)
455457
val cls = TypeDef(clsName, clsTmpl)
456-
.withMods(mods.toTypeFlags & AccessOrSynthetic | ModuleClassCreationFlags)
458+
.withMods(mods.toTypeFlags & RetainedModuleClassFlags | ModuleClassCreationFlags)
457459
Thicket(modul, classDef(cls))
458460
}
459461
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ object RefChecks {
287287
!member.isAnyOverride) {
288288
// (*) Exclusion for default getters, fixes SI-5178. We cannot assign the Override flag to
289289
// the default getter: one default getter might sometimes override, sometimes not. Example in comment on ticket.
290-
if (member.owner != clazz && other.owner != clazz && !(other.owner derivesFrom member.owner))
290+
if (member.name == nme.isDefined && member.is(Synthetic)) // isDefined methods are added automatially, can't have an override preset.
291+
member.setFlag(Override)
292+
else if (member.owner != clazz && other.owner != clazz && !(other.owner derivesFrom member.owner))
291293
emitOverrideError(
292294
clazz + " inherits conflicting members:\n "
293295
+ infoStringWithLocation(other) + " and\n " + infoStringWithLocation(member)

test/dotc/scala-collections.whitelist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
./scala-scala/src/library/scala/NotNull.scala
5454

5555
# https://github.com/lampepfl/dotty/issues/911
56-
#./scala-scala/src/library/scala/Option.scala
56+
./scala-scala/src/library/scala/Option.scala
5757

5858
./scala-scala/src/library/scala/PartialFunction.scala
5959
./scala-scala/src/library/scala/Predef.scala

0 commit comments

Comments
 (0)