File tree Expand file tree Collapse file tree 5 files changed +30
-8
lines changed
compiler/src/dotty/tools/dotc/transform/init Expand file tree Collapse file tree 5 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -101,8 +101,22 @@ object Errors:
101101 error.show
102102
103103 /** 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 :
105105 def show (using Context ): String =
106- " Problematic object instantiation with uninitialized arguments. " + stacktrace() + " \n " +
106+ " Problematic object instantiation: " + argumentInfo() + stacktrace() + " \n " +
107107 " It leads to the following error during object initialization:\n " +
108108 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:
784784 warm.callConstructor(ctor, argInfos2)
785785 }
786786 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)
788796 reporter.report(error)
789797 Hot
790798 else
Original file line number Diff line number Diff line change 11-- Error: tests/init/neg/cycle-structure.scala:9:13 --------------------------------------------------------------------
229 | val x = A(this) // error
33 | ^^^^^^^
4- | Problematic object instantiation with uninitialized arguments . Calling trace:
4+ | Problematic object instantiation: arg 1 is not fully initialized . Calling trace:
55 | -> case class B(a: A) { [ cycle-structure.scala:7 ]
66 | ^
77 | -> val x = A(this) // error [ cycle-structure.scala:9 ]
1616-- Error: tests/init/neg/cycle-structure.scala:3:13 --------------------------------------------------------------------
17173 | val x = B(this) // error
1818 | ^^^^^^^
19- | Problematic object instantiation with uninitialized arguments . Calling trace:
19+ | Problematic object instantiation: arg 1 is not fully initialized . Calling trace:
2020 | -> case class A(b: B) { [ cycle-structure.scala:1 ]
2121 | ^
2222 | -> val x = B(this) // error [ cycle-structure.scala:3 ]
Original file line number Diff line number Diff line change 11-- Error: tests/init/neg/i15363.scala:3:10 -----------------------------------------------------------------------------
223 | val b = new B(this) // error
33 | ^^^^^^^^^^^
4- | Problematic object instantiation with uninitialized arguments . Calling trace:
4+ | Problematic object instantiation: arg 1 is not fully initialized . Calling trace:
55 | -> class A: [ i15363.scala:1 ]
66 | ^
77 | -> val b = new B(this) // error [ i15363.scala:3 ]
Original file line number Diff line number Diff line change 11-- Error: tests/init/neg/secondary-ctor4.scala:54:14 -------------------------------------------------------------------
2254 | val c = new C(b, 5) // error
33 | ^^^^^^^^^^^
4- | Problematic object instantiation with uninitialized arguments . Calling trace:
4+ | Problematic object instantiation: the outer and arg 1 are not fully initialized . Calling trace:
55 | -> class N(d: D) extends M(d) { [ secondary-ctor4.scala:59 ]
66 | ^
77 | -> def this(d: D) = { [ secondary-ctor4.scala:7 ]
3030-- Error: tests/init/neg/secondary-ctor4.scala:42:4 --------------------------------------------------------------------
313142 | new A(new B(new D)) // error
3232 | ^^^^^^^^^^^^^^^^^^^
33- | Problematic object instantiation with uninitialized arguments . Calling trace:
33+ | Problematic object instantiation: the outer and arg 1 are not fully initialized . Calling trace:
3434 | -> class N(d: D) extends M(d) { [ secondary-ctor4.scala:59 ]
3535 | ^
3636 | -> def this(d: D) = { [ secondary-ctor4.scala:7 ]
You can’t perform that action at this time.
0 commit comments