@@ -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 }
0 commit comments