Commit 3138600
committed
Supress safe initialization warning in Run class
Due to the `this` pointer being passed to `start.setRun` in a function called during initialization, the initialization checker cannot prove that `this` is fully initialized.
We would get the following error:
```
[error] -- Error: /*******/dotty/compiler/src/dotty/tools/dotc/Run.scala:84:17
[error] 84 | start.setRun(this)
[error] | ^^^^
[error] |Cannot prove that the value is fully initialized. Only initialized values may be used as arguments. Calling trace:
[error] | -> val run = new Run(this, initCtx) { [ ReplCompiler.scala:42 ]
[error] | -> class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {iler-b[ Run.scala:38 ]
[error] | -> private var myCtx = rootContext(using ictx) [ Run.scala:89 ]
[error] | -> val rootCtx = super.rootContext.fresh [ ReplCompiler.scala:62 ]
```
The call to `start.setRun` stores the reference to `this` in a store without accessing any of its fields. The instance of `Run` referrred to by `this` will be fully initialized immediately after that function call. Thus, we are able to safely mark `this` as `@unchecked` without worrying about uninitialized members of the `Run` instance being accessed.
Review by @liufengyun1 parent ddac928 commit 3138600
1 file changed
+36
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 60 | | |
88 | 61 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 62 | | |
96 | 63 | | |
97 | 64 | | |
| |||
369 | 336 | | |
370 | 337 | | |
371 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
372 | 375 | | |
0 commit comments