File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
compiler/src/dotty/tools/dotc/cc
tests/neg-custom-args/captures Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -922,8 +922,12 @@ object OnlyCapability:
922922
923923 def unapply (tree : AnnotatedType )(using Context ): Option [(Type , ClassSymbol )] = tree match
924924 case AnnotatedType (parent : Type , ann) if ann.hasSymbol(defn.OnlyCapabilityAnnot ) =>
925- ann.tree.tpe.argTypes.head.classSymbol match
926- case cls : ClassSymbol => Some ((parent, cls))
925+ val arg = ann.tree.tpe.argTypes.head
926+ arg match
927+ case tp : TypeRef if tp.symbol.isClass =>
928+ tp.symbol match
929+ case cls : ClassSymbol => Some ((parent, cls))
930+ case _ => None
927931 case _ => None
928932 case _ => None
929933end OnlyCapability
Original file line number Diff line number Diff line change 1+ -- Error: tests/neg-custom-args/captures/classified-tp.scala:10:17 -----------------------------------------------------
2+ 10 | val c: AnyRef^{any.only[C]} = new AnyRef // error
3+ | ^^^^^^^^^^^
4+ | scala.caps.any.type @onlyCapability[C] is not a legal element of a capture set
5+ |
6+ | where: C is a type in method test with bounds <: B
7+ -- Error: tests/neg-custom-args/captures/classified-tp.scala:11:17 -----------------------------------------------------
8+ 11 | val d: AnyRef^{any.only[D]} = new AnyRef // error
9+ | ^^^^^^^^^^^
10+ | scala.caps.any.type @onlyCapability[D] is not a legal element of a capture set
11+ |
12+ | where: D is a type in method test with bounds <: scala.caps.Classifier
Original file line number Diff line number Diff line change 1+ import language .experimental .captureChecking
2+ import caps .*
3+
4+ trait A extends Classifier , SharedCapability
5+ trait B extends A , Classifier
6+
7+ def test [C <: B , D <: Classifier ] =
8+ val a : AnyRef ^ {any.only[A ]} = new AnyRef
9+ val b : AnyRef ^ {any.only[B ]} = new AnyRef
10+ val c : AnyRef ^ {any.only[C ]} = new AnyRef // error
11+ val d : AnyRef ^ {any.only[D ]} = new AnyRef // error
You can’t perform that action at this time.
0 commit comments