Skip to content

Commit 3e69a99

Browse files
committed
Respect @unchecked annotation
1 parent 4693e8d commit 3e69a99

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

compiler/src/dotty/tools/dotc/transform/init/Potentials.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ object Potentials {
140140

141141
def (ps: Potentials) select (symbol: Symbol, source: Tree)(implicit ctx: Context): Summary =
142142
ps.foldLeft(Summary.empty) { case ((pots, effs), pot) =>
143+
// max potential length
144+
// TODO: it can be specified on a project basis via compiler options
143145
if (pot.size > 2)
144146
(pots, effs + Leak(pot)(source))
145147
else if (symbol.isConstructor)

compiler/src/dotty/tools/dotc/transform/init/Summarization.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ object Summarization {
100100
}
101101

102102
case Typed(expr, tpt) =>
103-
analyze(expr)
103+
if (tpt.tpe.hasAnnotation(defn.UncheckedAnnot)) Summary.empty
104+
else analyze(expr)
104105

105106
case NamedArg(name, arg) =>
106107
analyze(arg)

tests/init/neg/lazylist2.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait LazyList[+A] {
77
}
88

99
object LazyList {
10-
inline implicit def toHelper[A](l: => LazyList[A]): Helper[A] = new Helper(l)
10+
implicit def toHelper[A](l: => LazyList[A]): Helper[A] = new Helper(l)
1111
final class Helper[A](l: => LazyList[A]) {
1212
def #:: [B >: A](elem: => B): LazyList[B] = new LazyList[B] {
1313
override def isEmpty: Boolean = false
@@ -21,7 +21,7 @@ import LazyList._
2121

2222
final class Test1 {
2323
lazy val a: LazyList[Int] = 5 #:: b
24-
val b: LazyList[Int] = 10 #:: a
24+
lazy val b: LazyList[Int] = 10 #:: a
2525

2626
a.head // ok
2727
b.head // ok
@@ -33,11 +33,11 @@ final class Test1 {
3333
final class Test2 {
3434
lazy val a: LazyList[Int] = 5 #:: b
3535
lazy val b: LazyList[Int] = 10 #:: 30 #:: c
36-
val c: LazyList[Int] = 20 #:: a
36+
lazy val c: LazyList[Int] = 20 #:: a
3737
}
3838

3939
final class Test3 {
40-
val a: LazyList[Int] = n #:: a
40+
val a: LazyList[Int] = n #:: (a: @unchecked)
4141
a.head
4242
val n: Int = 20 // error
4343
}

0 commit comments

Comments
 (0)