Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange warning with -Ysafe-init #14275

Closed
durban opened this issue Jan 14, 2022 · 1 comment · Fixed by #14352
Closed

Strange warning with -Ysafe-init #14275

durban opened this issue Jan 14, 2022 · 1 comment · Fixed by #14352

Comments

@durban
Copy link

durban commented Jan 14, 2022

Compiler version

3.1.0 (using -Ysafe-init)

Minimized code

final class MyClass(o: MyClass) {
  val other: MyClass = {
    if (o ne null) o
    else new MyClass(this)
  }
}

Output

[warn] -- Warning: .../TesT.scala:5:8 
[warn] 5 |    if (o ne null) o
[warn]   |        ^^^^^^^^^
[warn]   |Call method MyClass.this.o.ne(null) on a value with an unknown initialization. Calling trace:
[warn]   | -> else new MyClass(this)    [ TesT.scala:6 ]
[warn]   |   -> final class MyClass(o: MyClass) {       [ TesT.scala:3 ]
[warn] one warning found

Using eq instead of ne results in a similar warning.

Expectation

Unless I'm missing something, calling ne or eq is safe on any value (in fact, they can even be called on null). So I would expect no warning in these cases.

@Xavientois
Copy link
Contributor

I can try to fix this

Xavientois added a commit to Xavientois/dotty that referenced this issue Jan 25, 2022
Closes scala#14275

- Treats mehtods `ne`, `eq`, `isInstanceOf`, and `asInstanceOf` as safe
  to call, regardless of initialization

Review by @liufengyun
Xavientois added a commit to Xavientois/dotty that referenced this issue Feb 2, 2022
Closes scala#14275

- Treats mehtods `ne`, `eq`, `isInstanceOf`, and `asInstanceOf` as safe
  to call, regardless of initialization

Review by @liufengyun
Xavientois added a commit to Xavientois/dotty that referenced this issue Feb 2, 2022
Closes scala#14275

- Treats mehtods `ne`, `eq`, `isInstanceOf`, and `asInstanceOf` as safe
  to call, regardless of initialization

Review by @liufengyun
Xavientois added a commit to Xavientois/dotty that referenced this issue Feb 2, 2022
Closes scala#14275

- Treats mehtods `ne`, `eq`, `isInstanceOf`, and `asInstanceOf` as safe
  to call, regardless of initialization

Signed the CLA - @Xavientois

Review by @liufengyun
Xavientois added a commit to Xavientois/dotty that referenced this issue Feb 2, 2022
Closes scala#14275

- Treats mehtods `ne`, `eq`, `isInstanceOf`, and `asInstanceOf` as safe
  to call, regardless of initialization

Signed the CLA - @Xavientois

Review by @liufengyun
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
Closes scala#14275

- Treats mehtods `ne`, `eq`, `isInstanceOf`, and `asInstanceOf` as safe
  to call, regardless of initialization

Signed the CLA - @Xavientois

Review by @liufengyun
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants