File tree Expand file tree Collapse file tree 1 file changed +36
-38
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 1 file changed +36
-38
lines changed Original file line number Diff line number Diff line change @@ -1425,48 +1425,46 @@ trait Checking {
14251425 report.error(em " @ ${cls.name} needs a string literal as argument " , arg.srcPos)
14261426 tree
14271427 case _ =>
1428- checkAnnotTreeMap.transform(tree)
1429-
1430- private def checkAnnotTreeMap (using Context ) =
1431- new TreeMap :
1432- override def transform (tree : Tree )(using Context ): Tree =
1433- tree match
1434- case _ if tree.isType =>
1435- super .transform(tree)
1436- case _ : ( EmptyTree .type
1437- | Ident
1438- | Select
1439- | This
1440- | Super
1441- | Apply
1442- | TypeApply
1443- | Literal
1444- | New
1445- | Typed
1446- | NamedArg
1447- | Assign
1448- | Block
1449- | If
1450- | Closure
1451- | Return
1452- | SeqLiteral
1453- | Inlined
1454- | Quote
1455- | Splice
1456- | Hole
1457- | ValDef
1458- | DefDef
1459- | Annotated ) =>
1460- super .transform(tree)
1461- case _ =>
1428+ tree.find(! isValidAnnotSubtree(_)) match
1429+ case None => tree
1430+ case Some (invalidSubTree) =>
14621431 errorTree(
14631432 EmptyTree ,
1464- em """ Implementation restriction: this tree cannot be used in an annotation.
1465- |Tree: ${tree }
1466- |Type: ${tree .tpe}""" ,
1467- tree .srcPos
1433+ em """ Implementation restriction: expression cannot be used inside an annotation argument .
1434+ |Tree: ${invalidSubTree }
1435+ |Type: ${invalidSubTree .tpe}""" ,
1436+ invalidSubTree .srcPos
14681437 )
14691438
1439+ /** Returns `true` if this tree can appear inside an annotation argument. */
1440+ private def isValidAnnotSubtree (subTree : Tree ) =
1441+ subTree.isType || subTree.isInstanceOf [
1442+ EmptyTree .type
1443+ | Ident
1444+ | Select
1445+ | This
1446+ | Super
1447+ | Apply
1448+ | TypeApply
1449+ | Literal
1450+ | New
1451+ | Typed
1452+ | NamedArg
1453+ | Assign
1454+ | Block
1455+ | If
1456+ | Closure
1457+ | Return
1458+ | SeqLiteral
1459+ | Inlined
1460+ | Quote
1461+ | Splice
1462+ | Hole
1463+ | ValDef
1464+ | DefDef
1465+ | Annotated
1466+ ]
1467+
14701468 /** 1. Check that all case classes that extend `scala.reflect.Enum` are `enum` cases
14711469 * 2. Check that parameterised `enum` cases do not extend java.lang.Enum.
14721470 * 3. Check that only a static `enum` base class can extend java.lang.Enum.
You can’t perform that action at this time.
0 commit comments