Skip to content

Commit f663665

Browse files
committed
Make sealed an annotation
# Conflicts: # tests/pos-special/stdlib/collection/ArrayOps.scala
1 parent 84f313c commit f663665

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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

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

10441044
val rhs1 = typedAheadType(rhs)
1045-
val rhsBodyType: TypeBounds = addVariances(rhs1.tpe).toBounds
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+
10461053
val unsafeInfo = if (isDerived) rhsBodyType else abstracted(rhsBodyType)
10471054

10481055
def opaqueToBounds(info: Type): Type =

tests/neg/class-mods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ open final class Foo1 // error
22
sealed open class Foo2 // error
33

44
open type T1 // error
5-
sealed type T2 // error
5+
type T2 // ok
66
abstract type T3 // error
77
abstract open type T4 // error
88

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Ops[sealed A](xs: Array[A]) extends AnyVal:
2+
3+
def f(p: A => Boolean): Array[A] = xs

0 commit comments

Comments
 (0)