Skip to content

Commit e54c2ac

Browse files
committed
Drop support of sealed modifier on type parameters
1 parent e015c0c commit e54c2ac

File tree

8 files changed

+7
-49
lines changed

8 files changed

+7
-49
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ extension (tp: Type)
198198
case _: TypeRef | _: AppliedType => tp.typeSymbol.hasAnnotation(defn.CapabilityAnnot)
199199
case _ => false
200200

201-
def isSealed(using Context): Boolean = tp match
202-
case tp: TypeParamRef => tp.underlying.isSealed
203-
case tp: TypeBounds => tp.hi.hasAnnotation(defn.Caps_SealedAnnot)
204-
case tp: TypeRef => tp.symbol.is(Sealed) || tp.info.isSealed // TODO: drop symbol flag?
205-
case _ => false
206-
207201
/** Drop @retains annotations everywhere */
208202
def dropAllRetains(using Context): Type = // TODO we should drop retains from inferred types before unpickling
209203
val tm = new TypeMap:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ class Definitions {
993993
@tu lazy val Caps_unsafeBox: Symbol = CapsUnsafeModule.requiredMethod("unsafeBox")
994994
@tu lazy val Caps_unsafeUnbox: Symbol = CapsUnsafeModule.requiredMethod("unsafeUnbox")
995995
@tu lazy val Caps_unsafeBoxFunArg: Symbol = CapsUnsafeModule.requiredMethod("unsafeBoxFunArg")
996-
@tu lazy val Caps_SealedAnnot: ClassSymbol = requiredClass("scala.caps.Sealed")
997996
@tu lazy val expandedUniversalSet: CaptureSet = CaptureSet(captureRoot.termRef)
998997

999998
@tu lazy val PureClass: Symbol = requiredClass("scala.Pure")

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,15 +4072,10 @@ object Types {
40724072

40734073
protected def toPInfo(tp: Type)(using Context): PInfo
40744074

4075-
/** If `tparam` is a sealed type parameter symbol of a polymorphic method, add
4076-
* a @caps.Sealed annotation to the upperbound in `tp`.
4077-
*/
4078-
protected def addSealed(tparam: ParamInfo, tp: Type)(using Context): Type = tp
4079-
40804075
def fromParams[PI <: ParamInfo.Of[N]](params: List[PI], resultType: Type)(using Context): Type =
40814076
if (params.isEmpty) resultType
40824077
else apply(params.map(_.paramName))(
4083-
tl => params.map(param => toPInfo(addSealed(param, tl.integrate(params, param.paramInfo)))),
4078+
tl => params.map(param => toPInfo(tl.integrate(params, param.paramInfo))),
40844079
tl => tl.integrate(params, resultType))
40854080
}
40864081

@@ -4402,16 +4397,6 @@ object Types {
44024397
resultTypeExp: PolyType => Type)(using Context): PolyType =
44034398
unique(new PolyType(paramNames)(paramInfosExp, resultTypeExp))
44044399

4405-
override protected def addSealed(tparam: ParamInfo, tp: Type)(using Context): Type =
4406-
tparam match
4407-
case tparam: Symbol if tparam.is(Sealed) =>
4408-
tp match
4409-
case tp @ TypeBounds(lo, hi) =>
4410-
tp.derivedTypeBounds(lo,
4411-
AnnotatedType(hi, Annotation(defn.Caps_SealedAnnot, tparam.span)))
4412-
case _ => tp
4413-
case _ => tp
4414-
44154400
def unapply(tl: PolyType): Some[(List[LambdaParam], Type)] =
44164401
Some((tl.typeParams, tl.resType))
44174402
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,9 +3266,6 @@ object Parsers {
32663266
val start = in.offset
32673267
var mods = annotsAsMods() | Param
32683268
if ownerKind == ParamOwner.Class then mods |= PrivateLocal
3269-
if Feature.ccEnabled && in.token == SEALED then
3270-
mods |= Sealed
3271-
in.nextToken()
32723269
if isIdent(nme.raw.PLUS) && checkVarianceOK() then
32733270
mods |= Covariant
32743271
else if isIdent(nme.raw.MINUS) && checkVarianceOK() then

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,7 @@ object Checking {
519519
// but they can never be one of ClassOnlyFlags
520520
if !sym.isClass && sym.isOneOf(ClassOnlyFlags) then
521521
val illegal = sym.flags & ClassOnlyFlags
522-
if sym.is(TypeParam)
523-
&& illegal == Sealed
524-
&& Feature.ccEnabled && cc.ccConfig.allowUniversalInBoxed
525-
then () // OK
526-
else fail(em"only classes can be ${illegal.flagsString}")
522+
fail(em"only classes can be ${illegal.flagsString}")
527523
if (sym.is(AbsOverride) && !sym.owner.is(Trait))
528524
fail(AbstractOverrideOnlyInTraits(sym))
529525
if sym.is(Trait) then

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,7 @@ class Namer { typer: Typer =>
10421042
tp
10431043

10441044
val rhs1 = typedAheadType(rhs)
1045-
val rhsBodyType: TypeBounds =
1046-
val bounds = addVariances(rhs1.tpe).toBounds
1047-
if sym.is(Sealed) then
1048-
sym.resetFlag(Sealed)
1049-
bounds.derivedTypeBounds(bounds.lo,
1050-
AnnotatedType(bounds.hi, Annotation(defn.Caps_SealedAnnot, rhs1.span)))
1051-
else bounds
1052-
1045+
val rhsBodyType: TypeBounds = addVariances(rhs1.tpe).toBounds
10531046
val unsafeInfo = if (isDerived) rhsBodyType else abstracted(rhsBodyType)
10541047

10551048
def opaqueToBounds(info: Type): Type =

library/src/scala/caps.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,3 @@ import annotation.experimental
4444
def unsafeBoxFunArg: T => U = f
4545

4646
end unsafe
47-
48-
/** An annotation that expresses the sealed modifier on a type parameter
49-
* Should not be directly referred to in source
50-
*/
51-
@deprecated("The Sealed annotation should not be directly used in source code.\nUse the `sealed` modifier on type parameters instead.")
52-
class Sealed extends annotation.Annotation

tests/pos-special/stdlib/collection/ArrayOps.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ object ArrayOps {
121121
}
122122

123123
@SerialVersionUID(3L)
124-
private[collection] final class ArrayIterator[@specialized(Specializable.Everything) sealed A](xs: Array[A]) extends AbstractIterator[A] with Serializable {
124+
private[collection] final class ArrayIterator[@specialized(Specializable.Everything) A](xs: Array[A]) extends AbstractIterator[A] with Serializable {
125125
private[this] var pos = 0
126126
private[this] val len = xs.length
127127
override def knownSize: Int = len - pos
@@ -144,7 +144,7 @@ object ArrayOps {
144144
}
145145

146146
@SerialVersionUID(3L)
147-
private final class ReverseIterator[@specialized(Specializable.Everything) sealed A](xs: Array[A]) extends AbstractIterator[A] with Serializable {
147+
private final class ReverseIterator[@specialized(Specializable.Everything) A](xs: Array[A]) extends AbstractIterator[A] with Serializable {
148148
private[this] var pos = xs.length-1
149149
def hasNext: Boolean = pos >= 0
150150
def next(): A = {
@@ -777,7 +777,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
777777
* Returns `z` if this array is empty.
778778
*/
779779
def foldLeft[B](z: B)(op: (B, A) => B): B = {
780-
def f[@specialized(Specializable.Everything) sealed T](xs: Array[T], op: (Any, Any) => Any, z: Any): Any = {
780+
def f[@specialized(Specializable.Everything) T](xs: Array[T], op: (Any, Any) => Any, z: Any): Any = {
781781
val length = xs.length
782782
var v: Any = z
783783
var i = 0
@@ -883,7 +883,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
883883
* Returns `z` if this array is empty.
884884
*/
885885
def foldRight[B](z: B)(op: (A, B) => B): B = {
886-
def f[@specialized(Specializable.Everything) sealed T](xs: Array[T], op: (Any, Any) => Any, z: Any): Any = {
886+
def f[@specialized(Specializable.Everything) T](xs: Array[T], op: (Any, Any) => Any, z: Any): Any = {
887887
var v = z
888888
var i = xs.length - 1
889889
while(i >= 0) {

0 commit comments

Comments
 (0)