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

Nested mutable examples not running with Scala 2.13 #757

Closed
jroper opened this issue Jul 19, 2019 · 6 comments · Fixed by #826
Closed

Nested mutable examples not running with Scala 2.13 #757

jroper opened this issue Jul 19, 2019 · 6 comments · Fixed by #826

Comments

@jroper
Copy link

jroper commented Jul 19, 2019

This spec here:

https://github.com/jroper/play-geojson/blob/master/src/test/scala/au/id/jazzy/play/geojson/ExampleSpec.scala

Has examples nested two deep (ie, "foo" should { "do something" in { "bar" in { ... } } }. Using specs 4.6.0, this runs fine with Scala 2.11 and 2.12, but with 2.13, it doesn't run at all, it's as if the specs aren't there. Not sure if this is a Scala issue, specs2 issue, or if it's by design with Scala 2.13 and I need to update my specs.

@symbiont-eric-torreborre
Copy link
Contributor

Hi James, I'm on holidays at the moment for 10 more days. I will have a look at that when I come back and unfortunately I have no idea of what is wrong there (also kind of annoyed that the current test suite does not cover this case)

@etorreborre
Copy link
Owner

Actually I couldn't resist having a quick look. It seems that changing object ExampleSpec to class ExampleSpec fixes the issue. At least you have a work-around and I have a small reproducible case to investigate.

@jroper
Copy link
Author

jroper commented Jul 22, 2019

Thanks @etorreborre! Please enjoy your holiday, don't let my problems get in your way :)

jroper added a commit to jroper/play-geojson that referenced this issue Jul 22, 2019
@etorreborre
Copy link
Owner

Wow, I need further investigation but it seems that Scala 2.12 was actually buggy w.r.t the initialization of objects where the code in the body of an object would run twice and this would discover the spec fragments properly. Whereas in 2.13 the initialization of an object is done only once and now the code discovering the fragments is buggy. This can only encourage me to remove that complicated code which was only there to support a marginal feature.

jtjeferreira added a commit to jtjeferreira/scalaxb that referenced this issue Aug 25, 2019
fix tests to be class instead of object (see etorreborre/specs2#757)
Shadowfiend added a commit to lift/framework that referenced this issue Sep 15, 2019
Scala 2.13's singleton body evaluation semantics have changed, leading
to a failure to discover fragments inside a singleton spec (see
etorreborre/specs2#757).
Shadowfiend added a commit to lift/framework that referenced this issue Oct 10, 2019
Scala 2.13's singleton body evaluation semantics have changed, leading
to a failure to discover fragments inside a singleton spec (see
etorreborre/specs2#757).
@etorreborre
Copy link
Owner

I'm closing this issue. The code which is causing this will disappear anyway in the next major version of specs2.

xuwei-k added a commit to xuwei-k/unfiltered that referenced this issue Apr 22, 2020
xuwei-k added a commit to xuwei-k/specs2 that referenced this issue Apr 24, 2020
maybe scala/scala#7270 ?

```
package example

import scala.reflect.NameTransformer

object A{
  Main.a = 1
}

object B{
  Main.b = 1
}

object Main {
  var a: Int = 0
  var b: Int = 0

  def initializeByConstructor(): Int = {
    this.a = 0
    val List(constructor) = Class.forName("example.A$").getDeclaredConstructors.toList
    constructor.setAccessible(true)
    constructor.newInstance()
    val result = Main.a
    this.a = 0
    result
  }

  def initializeByMODULE_field(): Int = {
    this.b = 0
    Class.forName("example.B$").getDeclaredField(NameTransformer.MODULE_INSTANCE_NAME).get(null)
    val result = Main.b
    this.b = 0
    result
  }

  def main(args: Array[String]): Unit = {
    println((A, B))
    println(scala.util.Properties.versionString)
    println(initializeByConstructor())
    println(initializeByMODULE_field())
  }
}
```

```
[info] version 2.12.11
[info] 1
[info] 0
```

```
[info] version 2.13.2
[info] 0
[info] 0
```
@xuwei-k xuwei-k mentioned this issue Apr 24, 2020
@xuwei-k
Copy link
Contributor

xuwei-k commented Apr 24, 2020

#826 🙏

xuwei-k added a commit to scalikejdbc/scalikejdbc that referenced this issue Apr 25, 2020
xuwei-k added a commit to argonaut-io/argonaut that referenced this issue Apr 25, 2020
xuwei-k added a commit to xuwei-k/scalatra that referenced this issue Apr 25, 2020
etorreborre pushed a commit that referenced this issue Apr 26, 2020
maybe scala/scala#7270 ?

```
package example

import scala.reflect.NameTransformer

object A{
  Main.a = 1
}

object B{
  Main.b = 1
}

object Main {
  var a: Int = 0
  var b: Int = 0

  def initializeByConstructor(): Int = {
    this.a = 0
    val List(constructor) = Class.forName("example.A$").getDeclaredConstructors.toList
    constructor.setAccessible(true)
    constructor.newInstance()
    val result = Main.a
    this.a = 0
    result
  }

  def initializeByMODULE_field(): Int = {
    this.b = 0
    Class.forName("example.B$").getDeclaredField(NameTransformer.MODULE_INSTANCE_NAME).get(null)
    val result = Main.b
    this.b = 0
    result
  }

  def main(args: Array[String]): Unit = {
    println((A, B))
    println(scala.util.Properties.versionString)
    println(initializeByConstructor())
    println(initializeByMODULE_field())
  }
}
```

```
[info] version 2.12.11
[info] 1
[info] 0
```

```
[info] version 2.13.2
[info] 0
[info] 0
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants