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

Macro-related crash with -Ysafe-init for test class hierarchy #19649

Closed
martin-ockajak opened this issue Feb 8, 2024 · 8 comments
Closed

Macro-related crash with -Ysafe-init for test class hierarchy #19649

martin-ockajak opened this issue Feb 8, 2024 · 8 comments

Comments

@martin-ockajak
Copy link

martin-ockajak commented Feb 8, 2024

Compiler version

  • 3.3.2-RC2
  • 3.3.2-RC1
  • 3.3.1

The problem does not occur in the following compiler versions:

  • 3.3.0
  • 3.4.0-RC1
  • 3.4.0-RC4
  • 3.4.1-RC1-bin-20240201-95266f2-NIGHTLY

Compiler flags

-Ysafe-init

Minimized code

build.sbt

lazy val root = project.in(file(".")).settings(
  scalaVersion := "3.3.2-RC2",
  scalacOptions += "-Ysafe-init",
  libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.17"
)

AB.scala

trait A extends AnyFreeSpecLike:
  "" in {}

trait B extends A:
  val test = ()

C.scala (test)

class C extends B

Output (click arrow to expand)

[Internal error] unexpected tree

[error] /home/owner/safe-init-error/dotty/freespec/target/scala-3/src_managed/main/org/scalatest/freespec/AnyFreeSpecLike.scala: [Internal error] unexpected tree
[error] -> class C extends B    [ C.scala:1 ]
[error]    ^^^^^^^^^^^^^^^^^
[error] -> implicit inline def convertToFreeSpecStringWrapper(s: String):
[error]   AnyFreeSpecLike.this.FreeSpecStringWrapper =
[error]   {
[error]     ${
[error]       {
[error]         def $anonfun(using evidence$3: quoted.Quotes):
[error]           quoted.Expr[AnyFreeSpecLike.this.FreeSpecStringWrapper] =
[error]           org.scalactic.source.Position.withPosition[
[error]             AnyFreeSpecLike.this.FreeSpecStringWrapper](
[error]             '{
[error]               {
[error]                 def $anonfun(pos: org.scalactic.source.Position):
[error]                   AnyFreeSpecLike.this.FreeSpecStringWrapper =
[error]                   {
[error]                     new AnyFreeSpecLike.this.FreeSpecStringWrapper(s, pos)
[error]                   }
[error]                 closure($anonfun)
[error]               }
[error]             }.apply(evidence$3)
[error]           )(evidence$3,
[error]             quoted.Type.of[AnyFreeSpecLike.this.FreeSpecStringWrapper](
[error]               evidence$3)
[error]           )
[error]         closure($anonfun)
[error]       }
[error]     }
[error]   }:AnyFreeSpecLike.this.FreeSpecStringWrapper
[error] one error found

Reproduce

Unpack the attached archive and run the tests:

tar xfvz safe-init-error.tar.gz
cd safe-init-error
sbt test

safe-init-error.tar.gz

Note

Thanks for making a great compiler 😄 .

@martin-ockajak martin-ockajak added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 8, 2024
@liufengyun liufengyun self-assigned this Feb 9, 2024
@liufengyun
Copy link
Contributor

This should have been fixed in #18848. Can you try the nightly or a recent release of Scala 3, such as 3.4.0-RC4.

Maybe the fix should be back-ported as well.

Related: #18407

@liufengyun liufengyun added area:initialization and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 9, 2024
@martin-ockajak
Copy link
Author

martin-ockajak commented Feb 9, 2024

@liufengyun I can confirm that the problem does not occur in the following compiler versions:

  • 3.4.0-RC1
  • 3.4.0-RC4
  • 3.4.1-RC1-bin-20240201-95266f2-NIGHTLY

And indeed was this problem was previously detected by the community build in #18407 👍 and fixed in #18848.

It would be great to backport this fix to the upcoming 3.3.2 or 3.3.3 because as a library author I need to use the compiler version 3.3 (LTS) and safe initialization checking is a helpful feature which I would like to keep using. Thanks.

@liufengyun
Copy link
Contributor

I'm not familiar with the process for back-porting. Could you please adivse? /cc: @Kordyjan

@Kordyjan
Copy link
Contributor

I'm not that familiar with -Ysafe-init. I thought it was an unstable feature of the compiler and could only be used with the nightly releases.
If I was mistaken then it means that we should backport that fix to 3.3.3.

@martin-ockajak
Copy link
Author

The compiler options documentation mentions that it's a private setting with limited support. If this means it should not be considered an official part of the compiler user interface then I can just stop using it and nothing needs to be done.

@Kordyjan
Copy link
Contributor

I asked people around and now I can confidently say that -Y settings are indeed private and come without any guarantees.

There is ongoing discussion how should they be treated in LTS (supported, disabled, emitting warning or left as they are right now). I'm leaning on the side of supporting them. I'll update this comment when there will be a decision.

@martin-ockajak
Copy link
Author

@Kordyjan Thanks for looking into it 😄

@liufengyun
Copy link
Contributor

Given that #20199 is merged, this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants