Skip to content

Commit 6443cba

Browse files
authored
Merge pull request #10243 from dotty-staging/fix-#10239
Fix #10239: `@mixin trait` instead of `super trait`
2 parents 819e0b1 + 5245ff2 commit 6443cba

File tree

24 files changed

+62
-93
lines changed

24 files changed

+62
-93
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
213213
case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline)
214214

215215
case class Transparent()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.EmptyFlags)
216-
217-
case class Super()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.SuperTrait)
218216
}
219217

220218
/** Modifiers and annotations for definitions

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,35 +286,35 @@ trait ConstraintHandling {
286286
}
287287
}
288288

289-
/** If `tp` is an intersection such that some operands are super trait instances
290-
* and others are not, replace as many super trait instances as possible with Any
289+
/** If `tp` is an intersection such that some operands are mixin trait instances
290+
* and others are not, replace as many mixin trait instances as possible with Any
291291
* as long as the result is still a subtype of `bound`. But fall back to the
292292
* original type if the resulting widened type is a supertype of all dropped
293-
* types (since in this case the type was not a true intersection of super traits
293+
* types (since in this case the type was not a true intersection of mixin traits
294294
* and other types to start with).
295295
*/
296-
def dropSuperTraits(tp: Type, bound: Type)(using Context): Type =
296+
def dropMixinTraits(tp: Type, bound: Type)(using Context): Type =
297297
var kept: Set[Type] = Set() // types to keep since otherwise bound would not fit
298298
var dropped: List[Type] = List() // the types dropped so far, last one on top
299299

300-
def dropOneSuperTrait(tp: Type): Type =
300+
def dropOneMixinTrait(tp: Type): Type =
301301
val tpd = tp.dealias
302-
if tpd.typeSymbol.isSuperTrait && !tpd.isLambdaSub && !kept.contains(tpd) then
302+
if tpd.typeSymbol.isMixinTrait && !tpd.isLambdaSub && !kept.contains(tpd) then
303303
dropped = tpd :: dropped
304304
defn.AnyType
305305
else tpd match
306306
case AndType(tp1, tp2) =>
307-
val tp1w = dropOneSuperTrait(tp1)
307+
val tp1w = dropOneMixinTrait(tp1)
308308
if tp1w ne tp1 then tp1w & tp2
309309
else
310-
val tp2w = dropOneSuperTrait(tp2)
310+
val tp2w = dropOneMixinTrait(tp2)
311311
if tp2w ne tp2 then tp1 & tp2w
312312
else tpd
313313
case _ =>
314314
tp
315315

316316
def recur(tp: Type): Type =
317-
val tpw = dropOneSuperTrait(tp)
317+
val tpw = dropOneMixinTrait(tp)
318318
if tpw eq tp then tp
319319
else if tpw <:< bound then recur(tpw)
320320
else
@@ -324,15 +324,15 @@ trait ConstraintHandling {
324324

325325
val tpw = recur(tp)
326326
if (tpw eq tp) || dropped.forall(_ frozen_<:< tpw) then tp else tpw
327-
end dropSuperTraits
327+
end dropMixinTraits
328328

329329
/** Widen inferred type `inst` with upper `bound`, according to the following rules:
330330
* 1. If `inst` is a singleton type, or a union containing some singleton types,
331331
* widen (all) the singleton type(s), provided the result is a subtype of `bound`
332332
* (i.e. `inst.widenSingletons <:< bound` succeeds with satisfiable constraint)
333333
* 2. If `inst` is a union type, approximate the union type from above by an intersection
334334
* of all common base types, provided the result is a subtype of `bound`.
335-
* 3. drop super traits from intersections (see @dropSuperTraits)
335+
* 3. drop mixin traits from intersections (see @dropMixinTraits)
336336
*
337337
* Don't do these widenings if `bound` is a subtype of `scala.Singleton`.
338338
* Also, if the result of these widenings is a TypeRef to a module class,
@@ -357,7 +357,7 @@ trait ConstraintHandling {
357357

358358
val wideInst =
359359
if isSingleton(bound) then inst
360-
else dropSuperTraits(widenOr(widenSingle(inst)), bound)
360+
else dropMixinTraits(widenOr(widenSingle(inst)), bound)
361361
wideInst match
362362
case wideInst: TypeRef if wideInst.symbol.is(Module) =>
363363
TermRef(wideInst.prefix, wideInst.symbol.sourceModule)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ class Definitions {
909909
@tu lazy val InvariantBetweenAnnot: ClassSymbol = requiredClass("scala.annotation.internal.InvariantBetween")
910910
@tu lazy val MainAnnot: ClassSymbol = requiredClass("scala.main")
911911
@tu lazy val MigrationAnnot: ClassSymbol = requiredClass("scala.annotation.migration")
912+
@tu lazy val MixinAnnot: ClassSymbol = requiredClass("scala.annotation.mixin")
912913
@tu lazy val NativeAnnot: ClassSymbol = requiredClass("scala.native")
913914
@tu lazy val RepeatedAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Repeated")
914915
@tu lazy val SourceFileAnnot: ClassSymbol = requiredClass("scala.annotation.internal.SourceFile")
@@ -917,7 +918,6 @@ class Definitions {
917918
@tu lazy val ScalaStrictFPAnnot: ClassSymbol = requiredClass("scala.annotation.strictfp")
918919
@tu lazy val ScalaStaticAnnot: ClassSymbol = requiredClass("scala.annotation.static")
919920
@tu lazy val SerialVersionUIDAnnot: ClassSymbol = requiredClass("scala.SerialVersionUID")
920-
@tu lazy val SuperTraitAnnot: ClassSymbol = requiredClass("scala.annotation.superTrait")
921921
@tu lazy val TASTYSignatureAnnot: ClassSymbol = requiredClass("scala.annotation.internal.TASTYSignature")
922922
@tu lazy val TASTYLongSignatureAnnot: ClassSymbol = requiredClass("scala.annotation.internal.TASTYLongSignature")
923923
@tu lazy val TailrecAnnot: ClassSymbol = requiredClass("scala.annotation.tailrec")
@@ -1506,7 +1506,7 @@ class Definitions {
15061506
def isInfix(sym: Symbol)(using Context): Boolean =
15071507
(sym eq Object_eq) || (sym eq Object_ne)
15081508

1509-
@tu lazy val assumedSuperTraits =
1509+
@tu lazy val assumedMixinTraits =
15101510
Set(ComparableClass, ProductClass, SerializableClass,
15111511
// add these for now, until we had a chance to retrofit 2.13 stdlib
15121512
// we should do a more through sweep through it then.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ object Flags {
227227
val (Final @ _, _, _) = newFlags(6, "final")
228228

229229
/** A method symbol / a super trait */
230-
val (_, Method @ _, SuperTrait @ _) = newFlags(7, "<method>", "super")
230+
val (_, Method @ _, _) = newFlags(7, "<method>")
231231

232232
/** A (term or type) parameter to a class or method */
233233
val (Param @ _, TermParam @ _, TypeParam @ _) = newFlags(8, "<param>")
@@ -437,8 +437,7 @@ object Flags {
437437
* TODO: Should check that FromStartFlags do not change in completion
438438
*/
439439
val FromStartFlags: FlagSet = commonFlags(
440-
Module, Package, Deferred, Method, Case, Enum,
441-
SuperTrait, Param, ParamAccessor,
440+
Module, Package, Deferred, Method, Case, Enum, Param, ParamAccessor,
442441
Scala2SpecialFlags, MutableOrOpen, Opaque, Touched, JavaStatic,
443442
OuterOrCovariant, LabelOrContravariant, CaseAccessor,
444443
Extension, NonMember, Implicit, Given, Permanent, Synthetic,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,11 +1095,9 @@ object SymDenotations {
10951095
final def isEffectivelySealed(using Context): Boolean =
10961096
isOneOf(FinalOrSealed) || isClass && !isOneOf(EffectivelyOpenFlags)
10971097

1098-
final def isSuperTrait(using Context): Boolean =
1098+
final def isMixinTrait(using Context): Boolean =
10991099
isClass
1100-
&& (is(SuperTrait)
1101-
|| defn.assumedSuperTraits.contains(symbol.asClass)
1102-
|| hasAnnotation(defn.SuperTraitAnnot))
1100+
&& (hasAnnotation(defn.MixinAnnot) || defn.assumedMixinTraits.contains(symbol.asClass))
11031101

11041102
/** The class containing this denotation which has the given effective name. */
11051103
final def enclosingClassNamed(name: Name)(using Context): Symbol = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,8 +2638,8 @@ object TypeComparer {
26382638
def widenInferred(inst: Type, bound: Type)(using Context): Type =
26392639
comparing(_.widenInferred(inst, bound))
26402640

2641-
def dropSuperTraits(tp: Type, bound: Type)(using Context): Type =
2642-
comparing(_.dropSuperTraits(tp, bound))
2641+
def dropMixinTraits(tp: Type, bound: Type)(using Context): Type =
2642+
comparing(_.dropMixinTraits(tp, bound))
26432643

26442644
def constrainPatternType(pat: Type, scrut: Type)(using Context): Boolean =
26452645
comparing(_.constrainPatternType(pat, scrut))

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,6 @@ class TreePickler(pickler: TastyPickler) {
729729
if (flags.is(Sealed)) writeModTag(SEALED)
730730
if (flags.is(Abstract)) writeModTag(ABSTRACT)
731731
if (flags.is(Trait)) writeModTag(TRAIT)
732-
if flags.is(SuperTrait) then writeModTag(SUPERTRAIT)
733732
if (flags.is(Covariant)) writeModTag(COVARIANT)
734733
if (flags.is(Contravariant)) writeModTag(CONTRAVARIANT)
735734
if (flags.is(Opaque)) writeModTag(OPAQUE)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ class TreeUnpickler(reader: TastyReader,
648648
case STATIC => addFlag(JavaStatic)
649649
case OBJECT => addFlag(Module)
650650
case TRAIT => addFlag(Trait)
651-
case SUPERTRAIT => addFlag(SuperTrait)
652651
case ENUM => addFlag(Enum)
653652
case LOCAL => addFlag(Local)
654653
case SYNTHETIC => addFlag(Synthetic)
@@ -672,6 +671,9 @@ class TreeUnpickler(reader: TastyReader,
672671
case PROTECTEDqualified =>
673672
addFlag(Protected)
674673
privateWithin = readWithin
674+
case SUPERTRAIT =>
675+
readByte()
676+
annotFns = (_ => Annotation(defn.MixinAnnot)) :: annotFns
675677
case ANNOTATION =>
676678
annotFns = readAnnot :: annotFns
677679
case tag =>

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,7 +3378,7 @@ object Parsers {
33783378
}
33793379
}
33803380

3381-
/** TmplDef ::= ([‘case’] ‘class’ | [‘super’] ‘trait’) ClassDef
3381+
/** TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
33823382
* | [‘case’] ‘object’ ObjectDef
33833383
* | ‘enum’ EnumDef
33843384
* | ‘given’ GivenDef
@@ -3388,8 +3388,6 @@ object Parsers {
33883388
in.token match {
33893389
case TRAIT =>
33903390
classDef(start, in.skipToken(addFlag(mods, Trait)))
3391-
case SUPERTRAIT =>
3392-
classDef(start, in.skipToken(addFlag(mods, Trait | SuperTrait)))
33933391
case CLASS =>
33943392
classDef(start, in.skipToken(mods))
33953393
case CASECLASS =>

0 commit comments

Comments
 (0)