Skip to content

Conversation

@Xavientois
Copy link
Contributor

@Xavientois Xavientois commented Feb 13, 2022

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 @liufengyun

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, LGTM

@Xavientois
Copy link
Contributor Author

I've put together an alternative fix here. If we decide that the other fix is good, I will close this PR.

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 @liufengyun
@Xavientois Xavientois force-pushed the fix-setRun-safe-init-warning branch from 413180a to 3138600 Compare February 14, 2022 21:23
@olhotak olhotak merged commit 019f0ee into scala:main Feb 15, 2022
@Xavientois Xavientois deleted the fix-setRun-safe-init-warning branch February 15, 2022 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants