@@ -1411,40 +1411,60 @@ abstract class RefChecks extends Transform {
1411
1411
false
1412
1412
}
1413
1413
1414
- private def checkTypeRef (tp : Type , tree : Tree , skipBounds : Boolean ) = tp match {
1415
- case TypeRef (pre, sym, args) =>
1416
- tree match {
1417
- case tt : TypeTree if tt.original == null => // scala/bug#7783 don't warn about inferred types
1418
- // FIXME: reconcile this check with one in resetAttrs
1419
- case _ => checkUndesiredProperties(sym, tree.pos)
1414
+ private object RefCheckTypeMap extends TypeMap {
1415
+ object ExistentialToWildcard extends TypeMap {
1416
+ override def apply (tpe : Type ): Type =
1417
+ if (tpe.typeSymbol.isExistential) WildcardType else mapOver(tpe)
1418
+ }
1419
+
1420
+ private [this ] var skipBounds = false
1421
+ private [this ] var tree : Tree = EmptyTree
1422
+
1423
+ def check (tpe : Type , tree : Tree ): Type = {
1424
+ this .tree = tree
1425
+ try apply(tpe) finally {
1426
+ skipBounds = false
1427
+ this .tree = EmptyTree
1420
1428
}
1421
- if (sym.isJavaDefined)
1422
- sym.typeParams foreach (_.cookJavaRawInfo())
1423
- if (! tp.isHigherKinded && ! skipBounds)
1424
- checkBounds(tree, pre, sym.owner, sym.typeParams, args)
1425
- case _ =>
1426
- }
1429
+ }
1427
1430
1428
- private def checkTypeRefBounds (tp : Type , tree : Tree ) = {
1429
- var skipBounds = false
1430
- tp match {
1431
- case AnnotatedType (ann :: Nil , underlying) if ann.symbol == UncheckedBoundsClass =>
1431
+ // check all bounds, except those that are existential type parameters
1432
+ // or those within typed annotated with @uncheckedBounds
1433
+ override def apply (tpe : Type ): Type = tpe match {
1434
+ case tpe : AnnotatedType if tpe.hasAnnotation(UncheckedBoundsClass ) =>
1435
+ // scala/bug#7694 Allow code synthesizers to disable checking of bounds for TypeTrees based on inferred LUBs
1436
+ // which might not conform to the constraints.
1437
+ val savedSkipBounds = skipBounds
1432
1438
skipBounds = true
1433
- underlying
1439
+ try mapOver(tpe).filterAnnotations(_.symbol != UncheckedBoundsClass )
1440
+ finally skipBounds = savedSkipBounds
1441
+ case tpe : TypeRef =>
1442
+ checkTypeRef(ExistentialToWildcard (tpe))
1443
+ mapOver(tpe)
1444
+ case tpe =>
1445
+ mapOver(tpe)
1446
+ }
1447
+
1448
+ private def checkTypeRef (tpe : Type ): Unit = tpe match {
1434
1449
case TypeRef (pre, sym, args) =>
1435
- if (! tp.isHigherKinded && ! skipBounds)
1450
+ tree match {
1451
+ // scala/bug#7783 don't warn about inferred types
1452
+ // FIXME: reconcile this check with one in resetAttrs
1453
+ case tree : TypeTree if tree.original == null =>
1454
+ case tree => checkUndesiredProperties(sym, tree.pos)
1455
+ }
1456
+ if (sym.isJavaDefined)
1457
+ sym.typeParams.foreach(_.cookJavaRawInfo())
1458
+ if (! tpe.isHigherKinded && ! skipBounds)
1436
1459
checkBounds(tree, pre, sym.owner, sym.typeParams, args)
1437
- tp
1438
1460
case _ =>
1439
- tp
1440
1461
}
1441
1462
}
1442
1463
1443
1464
private def applyRefchecksToAnnotations (tree : Tree ): Unit = {
1444
1465
def applyChecks (annots : List [AnnotationInfo ]): List [AnnotationInfo ] = if (annots.isEmpty) Nil else {
1445
1466
annots.foreach { ann =>
1446
- checkTypeRef(ann.tpe, tree, skipBounds = false )
1447
- checkTypeRefBounds(ann.tpe, tree)
1467
+ RefCheckTypeMap .check(ann.tpe, tree)
1448
1468
}
1449
1469
1450
1470
val annotsBySymbol = new mutable.LinkedHashMap [Symbol , ListBuffer [AnnotationInfo ]]()
@@ -1800,29 +1820,8 @@ abstract class RefChecks extends Transform {
1800
1820
}
1801
1821
}
1802
1822
1803
- val existentialParams = new ListBuffer [Symbol ]
1804
- var skipBounds = false
1805
- // check all bounds, except those that are existential type parameters
1806
- // or those within typed annotated with @uncheckedBounds
1807
- if (! inPattern) tree.tpe foreach {
1808
- case tp @ ExistentialType (tparams, tpe) =>
1809
- existentialParams ++= tparams
1810
- case ann : AnnotatedType if ann.hasAnnotation(UncheckedBoundsClass ) =>
1811
- // scala/bug#7694 Allow code synthesizers to disable checking of bounds for TypeTrees based on inferred LUBs
1812
- // which might not conform to the constraints.
1813
- skipBounds = true
1814
- case tp : TypeRef =>
1815
- val tpWithWildcards = deriveTypeWithWildcards(existentialParams.toList)(tp)
1816
- checkTypeRef(tpWithWildcards, tree, skipBounds)
1817
- case _ =>
1818
- }
1819
- if (skipBounds) {
1820
- tree.setType(tree.tpe.map {
1821
- _.filterAnnotations(_.symbol != UncheckedBoundsClass )
1822
- })
1823
- }
1824
-
1825
- tree
1823
+ if (inPattern) tree
1824
+ else tree.setType(RefCheckTypeMap .check(tree.tpe, tree))
1826
1825
1827
1826
case TypeApply (fn, args) =>
1828
1827
checkBounds(tree, NoPrefix , NoSymbol , fn.tpe.typeParams, args map (_.tpe))
@@ -1857,8 +1856,8 @@ abstract class RefChecks extends Transform {
1857
1856
case x @ Select (_, _) =>
1858
1857
transformSelect(x)
1859
1858
1860
- case Literal (Constant (tp : Type )) =>
1861
- checkTypeRef(tp , tree, skipBounds = false )
1859
+ case Literal (Constant (tpe : Type )) =>
1860
+ RefCheckTypeMap .check(tpe , tree)
1862
1861
tree
1863
1862
1864
1863
case UnApply (fun, args) =>
0 commit comments