Skip to content

Commit 4c36fbb

Browse files
committed
Make sealed an annotation
1 parent e033e94 commit 4c36fbb

File tree

4 files changed

+69
-58
lines changed

4 files changed

+69
-58
lines changed

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

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

10351035
val rhs1 = typedAheadType(rhs)
1036-
val rhsBodyType: TypeBounds = addVariances(rhs1.tpe).toBounds
1036+
val rhsBodyType: TypeBounds =
1037+
val bounds = addVariances(rhs1.tpe).toBounds
1038+
if sym.is(Sealed) then
1039+
sym.resetFlag(Sealed)
1040+
bounds.derivedTypeBounds(bounds.lo,
1041+
AnnotatedType(bounds.hi, Annotation(defn.Caps_SealedAnnot, rhs1.span)))
1042+
else bounds
1043+
10371044
val unsafeInfo = if (isDerived) rhsBodyType else abstracted(rhsBodyType)
10381045

10391046
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)