File tree 6 files changed +46
-8
lines changed
compiler/src/dotty/tools/dotc/transform/init
6 files changed +46
-8
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ object Errors {
60
60
case class AccessNonInit (field : Symbol , trace : Vector [Tree ]) extends Error {
61
61
def source : Tree = trace.last
62
62
def show (implicit ctx : Context ): String =
63
- " Access non-initialized field " + field.show + " ."
63
+ " Access non-initialized field " + field.name. show + " ."
64
64
65
65
override def report (implicit ctx : Context ): Unit = ctx.error(show + stacktrace, field.sourcePos)
66
66
}
Original file line number Diff line number Diff line change @@ -70,9 +70,13 @@ object Summarization {
70
70
val summary = analyze(fun)
71
71
val ignoredCall = env.ignoredMethods.contains(expr.symbol)
72
72
73
- val res = args.foldLeft(summary) { (sum, arg) =>
73
+ val argTps = fun.tpe.widen match
74
+ case mt : MethodType => mt.paramInfos
75
+
76
+ val res = args.zip(argTps).foldLeft(summary) { case (sum, (arg, argTp)) =>
74
77
val (pots1, effs1) = analyze(arg)
75
78
if (ignoredCall) sum.withEffs(effs1)
79
+ else if (argTp.isInstanceOf [ExprType ]) sum + Promote (Fun (pots1, effs1)(arg))(arg)
76
80
else sum.withEffs(pots1.promote(arg) ++ effs1)
77
81
}
78
82
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ class LazyList[A]
2
2
3
3
object LazyList {
4
4
inline implicit def toDeferred [A ](l : LazyList [A ]): Deferred [A ] =
5
- new Deferred (l)
5
+ new Deferred (l) // error
6
6
7
7
final class Deferred [A ](l : => LazyList [A ]) {
8
8
def #:: [B >: A ](elem : => B ): LazyList [B ] = ???
@@ -16,5 +16,5 @@ final class Test {
16
16
lazy val b : LazyList [Int ] = 10 #:: a
17
17
18
18
val x : LazyList [Int ] = 5 #:: y
19
- val y : LazyList [Int ] = 10 #:: x // error
19
+ val y : LazyList [Int ] = 10 #:: x
20
20
}
Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ final class Test1 {
26
26
a.head // ok
27
27
b.head // ok
28
28
29
- val x : LazyList [Int ] = 5 #:: y
30
- val y : LazyList [Int ] = 10 #:: x // error
29
+ val x : LazyList [Int ] = 5 #:: y // error
30
+ val y : LazyList [Int ] = 10 #:: x
31
31
}
32
32
33
33
final class Test2 {
@@ -37,7 +37,7 @@ final class Test2 {
37
37
}
38
38
39
39
final class Test3 {
40
- val a : LazyList [Int ] = n #:: (a : @ unchecked)
40
+ val a : LazyList [Int ] = n #:: (a : @ unchecked) // error
41
41
a.head
42
- val n : Int = 20 // error
42
+ val n : Int = 20
43
43
}
Original file line number Diff line number Diff line change
1
+ -- Error: tests/init/neg/t3273.scala:4:42 ------------------------------------------------------------------------------
2
+ 4 | val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error
3
+ | ^^^^^^^^^^^^^^^
4
+ | Promoting the value to fully-initialized is unsafe.
5
+ | Calling trace:
6
+ | -> val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error [ t3273.scala:4 ]
7
+ |
8
+ | The unsafe promotion may cause the following problem(s):
9
+ |
10
+ | 1. Access non-initialized field num1. Calling trace:
11
+ | -> val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error [ t3273.scala:4 ]
12
+ -- Error: tests/init/neg/t3273.scala:5:61 ------------------------------------------------------------------------------
13
+ 5 | val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error
14
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
+ | Promoting the value to fully-initialized is unsafe.
16
+ | Calling trace:
17
+ | -> val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error [ t3273.scala:5 ]
18
+ |
19
+ | The unsafe promotion may cause the following problem(s):
20
+ |
21
+ | 1. Access non-initialized field num2. Calling trace:
22
+ | -> val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error [ t3273.scala:5 ]
Original file line number Diff line number Diff line change
1
+ import scala .language .implicitConversions
2
+
3
+ object Test {
4
+ val num1 : LazyList [Int ] = 1 #:: num1.map(_ + 1 ) // error
5
+ val num2 : LazyList [Int ] = 1 #:: num2.iterator.map(_ + 1 ).to(LazyList ) // error
6
+
7
+ def main (args : Array [String ]): Unit = {
8
+ val x1 = (num1 take 10 ).toList
9
+ val x2 = (num2 take 10 ).toList
10
+ assert(x1 == x2)
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments