Skip to content

Commit 67017d7

Browse files
committed
Fix #10239: @mixin trait instead of super trait
1 parent 2df5dbb commit 67017d7

File tree

23 files changed

+61
-92
lines changed

23 files changed

+61
-92
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
@@ -916,6 +916,7 @@ class Definitions {
916916
@tu lazy val InvariantBetweenAnnot: ClassSymbol = requiredClass("scala.annotation.internal.InvariantBetween")
917917
@tu lazy val MainAnnot: ClassSymbol = requiredClass("scala.main")
918918
@tu lazy val MigrationAnnot: ClassSymbol = requiredClass("scala.annotation.migration")
919+
@tu lazy val MixinAnnot: ClassSymbol = requiredClass("scala.annotation.mixin")
919920
@tu lazy val NativeAnnot: ClassSymbol = requiredClass("scala.native")
920921
@tu lazy val RepeatedAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Repeated")
921922
@tu lazy val SourceFileAnnot: ClassSymbol = requiredClass("scala.annotation.internal.SourceFile")
@@ -924,7 +925,6 @@ class Definitions {
924925
@tu lazy val ScalaStrictFPAnnot: ClassSymbol = requiredClass("scala.annotation.strictfp")
925926
@tu lazy val ScalaStaticAnnot: ClassSymbol = requiredClass("scala.annotation.static")
926927
@tu lazy val SerialVersionUIDAnnot: ClassSymbol = requiredClass("scala.SerialVersionUID")
927-
@tu lazy val SuperTraitAnnot: ClassSymbol = requiredClass("scala.annotation.superTrait")
928928
@tu lazy val TASTYSignatureAnnot: ClassSymbol = requiredClass("scala.annotation.internal.TASTYSignature")
929929
@tu lazy val TASTYLongSignatureAnnot: ClassSymbol = requiredClass("scala.annotation.internal.TASTYLongSignature")
930930
@tu lazy val TailrecAnnot: ClassSymbol = requiredClass("scala.annotation.tailrec")
@@ -1513,7 +1513,7 @@ class Definitions {
15131513
def isInfix(sym: Symbol)(using Context): Boolean =
15141514
(sym eq Object_eq) || (sym eq Object_ne)
15151515

1516-
@tu lazy val assumedSuperTraits =
1516+
@tu lazy val assumedMixinTraits =
15171517
Set(ComparableClass, ProductClass, SerializableClass,
15181518
// add these for now, until we had a chance to retrofit 2.13 stdlib
15191519
// 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 =>

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ object Scanners {
554554
currentRegion = r.outer
555555
case _ =>
556556

557-
/** - Join CASE + CLASS => CASECLASS, CASE + OBJECT => CASEOBJECT, SUPER + TRAIT => SUPERTRAIT
557+
/** - Join CASE + CLASS => CASECLASS, CASE + OBJECT => CASEOBJECT
558558
* SEMI + ELSE => ELSE, COLON + <EOL> => COLONEOL
559559
* - Insert missing OUTDENTs at EOF
560560
*/
@@ -571,10 +571,6 @@ object Scanners {
571571
if (token == CLASS) fuse(CASECLASS)
572572
else if (token == OBJECT) fuse(CASEOBJECT)
573573
else reset()
574-
case SUPER =>
575-
lookAhead()
576-
if token == TRAIT then fuse(SUPERTRAIT)
577-
else reset()
578574
case SEMI =>
579575
lookAhead()
580576
if (token != ELSE) reset()

0 commit comments

Comments
 (0)