File tree 5 files changed +30
-8
lines changed
compiler/src/dotty/tools/dotc/transform/init
5 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -101,8 +101,22 @@ object Errors:
101
101
error.show
102
102
103
103
/** Unsafe leaking a non-hot value as constructor arguments */
104
- case class UnsafeLeaking (trace : Seq [Tree ], error : Error ) extends Error :
104
+ case class UnsafeLeaking (trace : Seq [Tree ], error : Error , argsIndices : List [ Int ] ) extends Error :
105
105
def show (using Context ): String =
106
- " Problematic object instantiation with uninitialized arguments. " + stacktrace() + " \n " +
106
+ " Problematic object instantiation: " + argumentInfo() + stacktrace() + " \n " +
107
107
" It leads to the following error during object initialization:\n " +
108
108
error.show
109
+
110
+ private def argumentInfo (): String =
111
+ val multiple = argsIndices.size > 1
112
+ val part1 =
113
+ argsIndices.zipWithIndex.foldLeft(" " ) { case (acc, (pos, i)) =>
114
+ val text1 = if pos == 0 then " the outer" else " arg " + pos.toString
115
+ val text2 =
116
+ if i == argsIndices.size - 2 then text1 + " and "
117
+ else if i == argsIndices.size - 1 then text1
118
+ else text1 + " , "
119
+ acc + text2
120
+ }
121
+ val part2 = if multiple then " are not fully initialized." else " is not fully initialized."
122
+ part1 + part2
Original file line number Diff line number Diff line change @@ -784,7 +784,15 @@ object Semantic:
784
784
warm.callConstructor(ctor, argInfos2)
785
785
}
786
786
if errors.nonEmpty then
787
- val error = UnsafeLeaking (trace.toVector, errors.head)
787
+ val indices =
788
+ for
789
+ (arg, i) <- argValues.zipWithIndex
790
+ if arg.isCold
791
+ yield
792
+ i + 1
793
+
794
+ val indices2 = if warm.outer.isHot then indices else 0 :: indices
795
+ val error = UnsafeLeaking (trace.toVector, errors.head, indices2)
788
796
reporter.report(error)
789
797
Hot
790
798
else
Original file line number Diff line number Diff line change 1
1
-- Error: tests/init/neg/cycle-structure.scala:9:13 --------------------------------------------------------------------
2
2
9 | val x = A(this) // error
3
3
| ^^^^^^^
4
- | Problematic object instantiation with uninitialized arguments . Calling trace:
4
+ | Problematic object instantiation: arg 1 is not fully initialized . Calling trace:
5
5
| -> case class B(a: A) { [ cycle-structure.scala:7 ]
6
6
| ^
7
7
| -> val x = A(this) // error [ cycle-structure.scala:9 ]
16
16
-- Error: tests/init/neg/cycle-structure.scala:3:13 --------------------------------------------------------------------
17
17
3 | val x = B(this) // error
18
18
| ^^^^^^^
19
- | Problematic object instantiation with uninitialized arguments . Calling trace:
19
+ | Problematic object instantiation: arg 1 is not fully initialized . Calling trace:
20
20
| -> case class A(b: B) { [ cycle-structure.scala:1 ]
21
21
| ^
22
22
| -> val x = B(this) // error [ cycle-structure.scala:3 ]
Original file line number Diff line number Diff line change 1
1
-- Error: tests/init/neg/i15363.scala:3:10 -----------------------------------------------------------------------------
2
2
3 | val b = new B(this) // error
3
3
| ^^^^^^^^^^^
4
- | Problematic object instantiation with uninitialized arguments . Calling trace:
4
+ | Problematic object instantiation: arg 1 is not fully initialized . Calling trace:
5
5
| -> class A: [ i15363.scala:1 ]
6
6
| ^
7
7
| -> val b = new B(this) // error [ i15363.scala:3 ]
Original file line number Diff line number Diff line change 1
1
-- Error: tests/init/neg/secondary-ctor4.scala:54:14 -------------------------------------------------------------------
2
2
54 | val c = new C(b, 5) // error
3
3
| ^^^^^^^^^^^
4
- | Problematic object instantiation with uninitialized arguments . Calling trace:
4
+ | Problematic object instantiation: the outer and arg 1 are not fully initialized . Calling trace:
5
5
| -> class N(d: D) extends M(d) { [ secondary-ctor4.scala:59 ]
6
6
| ^
7
7
| -> def this(d: D) = { [ secondary-ctor4.scala:7 ]
30
30
-- Error: tests/init/neg/secondary-ctor4.scala:42:4 --------------------------------------------------------------------
31
31
42 | new A(new B(new D)) // error
32
32
| ^^^^^^^^^^^^^^^^^^^
33
- | Problematic object instantiation with uninitialized arguments . Calling trace:
33
+ | Problematic object instantiation: the outer and arg 1 are not fully initialized . Calling trace:
34
34
| -> class N(d: D) extends M(d) { [ secondary-ctor4.scala:59 ]
35
35
| ^
36
36
| -> def this(d: D) = { [ secondary-ctor4.scala:7 ]
You can’t perform that action at this time.
0 commit comments