File tree Expand file tree Collapse file tree 3 files changed +30
-18
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +30
-18
lines changed Original file line number Diff line number Diff line change @@ -240,8 +240,15 @@ trait QuotesAndSplices {
240
240
TypeTree (tree.tpe.dealias).withSpan(tree.span)
241
241
else
242
242
tree
243
- case tdef : TypeDef if tdef.symbol.hasAnnotation(defn.InternalQuoted_patternTypeAnnot ) =>
244
- transformTypeBindingTypeDef(tdef, typePatBuf)
243
+ case tdef : TypeDef =>
244
+ if tdef.symbol.hasAnnotation(defn.InternalQuoted_patternTypeAnnot ) then
245
+ transformTypeBindingTypeDef(tdef, typePatBuf)
246
+ else if tdef.symbol.isClass then
247
+ val kind = if tdef.symbol.is(Module ) then " objects" else " classes"
248
+ ctx.error(" Implementation restriction: cannot match " + kind, tree.sourcePos)
249
+ EmptyTree
250
+ else
251
+ super .transform(tree)
245
252
case tree @ AppliedTypeTree (tpt, args) =>
246
253
val args1 : List [Tree ] = args.zipWithConserve(tpt.tpe.typeParams.map(_.paramVarianceSign)) { (arg, v) =>
247
254
arg.tpe match {
@@ -254,6 +261,15 @@ trait QuotesAndSplices {
254
261
if tree.name.isTermName && ! tree.nameSpan.isSynthetic && tree.name.startsWith(" $" ) then
255
262
ctx.error(" Names cannot start with $ quote pattern " , tree.namePos)
256
263
super .transform(tree)
264
+ case _ : Match =>
265
+ ctx.error(" Implementation restriction: cannot match `match` expressions" , tree.sourcePos)
266
+ EmptyTree
267
+ case _ : Try =>
268
+ ctx.error(" Implementation restriction: cannot match `try` expressions" , tree.sourcePos)
269
+ EmptyTree
270
+ case _ : Return =>
271
+ ctx.error(" Implementation restriction: cannot match `return` statements" , tree.sourcePos)
272
+ EmptyTree
257
273
case _ =>
258
274
super .transform(tree)
259
275
}
Original file line number Diff line number Diff line change
1
+ import scala .quoted ._
2
+
3
+ def f (x : Expr [Any ])(using QuoteContext ) =
4
+ x match {
5
+ case ' { class Foo ; () } => // error
6
+ case ' { object Foo ; () } => // error
7
+ case ' { 1 match { case _ => () } } => // error
8
+ case ' { try 1 finally () } => // error
9
+ case ' { try 1 catch { case _ => 4 } } => // error
10
+ case ' { Nil .map({ case x : Int => () }) } => // error
11
+ case ' { def f : Int = return 2 } => // error
12
+ }
Original file line number Diff line number Diff line change @@ -42,22 +42,6 @@ object Lib {
42
42
z : Expr [T & Int ]
43
43
e
44
44
45
- case e @ ' { ($x : Boolean ) match { case _ => $y : Int } } =>
46
- e : Expr [T & Int ]
47
- y : Expr [T & Int ]
48
- e
49
-
50
- case e @ ' { ($x : Boolean ) match { case _ => $y } } =>
51
- e : Expr [T ]
52
- y : Expr [T ]
53
- e
54
-
55
- case e @ ' { try ($x : Boolean ) catch { case _ => $y : Int } } =>
56
- e : Expr [T & (Boolean | Int )]
57
- x : Expr [T & Boolean ]
58
- y : Expr [T & Int ]
59
- e
60
-
61
45
}
62
46
}
63
47
}
You can’t perform that action at this time.
0 commit comments