scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
231 stars 21 forks source link

scalac assertion in icode phase using Scalatest's diagrammed assertion macro #8809

Closed scabug closed 10 years ago

scabug commented 10 years ago

Trying to compile the following code using scala2.11.2 and scalatest-2.2.1 gives me the attached error stacktrace. (Same behaviour in scala-2.10.4 and scalatest-2.2.0). Everything works as expected after either

class PossibleScalacBug extends FunSpec with DiagrammedAssertions {
  it("returns 42 as the total count") {
    assert(StubRepository.totalCountFor(new FakeLocalDate(2014, 8, 8)) == 42)
  }
}

object StubRepository {
  def totalCountFor(unusedDate: FakeLocalDate): Int = 42
}

class FakeLocalDate(year: Int, month: Int, day: Int)
scabug commented 10 years ago

Imported From: https://issues.scala-lang.org/browse/SI-8809?orig=1 Reporter: Markus Stoy (mstoy) Affected Versions: 2.10.4, 2.11.2 Attachments:

scabug commented 10 years ago

@retronym said: This looks like a bug in Scalatest's assert macro.

/cc [~cheeseng]

Here's a minimal reproduction:

% tail build.sbt test.scala
==> build.sbt <==
scalaVersion := "2.11.2"

libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.1"

==> test.scala <==
import org.scalatest._

class PossibleScalacBug {
  import DiagrammedAssertions._
  assert(new Object() == "")
}

% sbt compile
[info] Loading global plugins from /Users/jason/.sbt/0.13/plugins
[info] Loading project definition from /Users/jason/code/scratch3/project
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Compiling 1 Scala source to /Users/jason/code/scratch3/target/scala-2.11/classes...
[error]
[error]   Unexpected New(TypeTree(class Object)/Object) received in icode.
[error]   Call was genLoad(new Object,package <empty> { class PossibleScalacBug { def PossibleScalacBug.<init> { bb=1 } } },REF(class Object))
[error]      while compiling: /Users/jason/code/scratch3/test.scala
[error]         during phase: icode
...
scabug commented 10 years ago

Chua Chee Seng (cheeseng) said: Thanks Jason, I'll take a look.

scabug commented 10 years ago

Chua Chee Seng (cheeseng) said: fyi, I submitted a pull request to fix in ScalaTest:

https://github.com/scalatest/scalatest/pull/371

Hopefully it will be pulled and and be included in 2.2.3 release.

Thanks for letting use know the problem!

scabug commented 10 years ago

@bvenners said: Markus,

I made a 2.2.3-SNAP1 release with the fix for this. Can you try it and verify it works for you?

Thanks.

https://oss.sonatype.org/content/groups/public/org/scalatest/scalatest_2.11/2.2.3-SNAP1/

Bill

scabug commented 10 years ago

Markus Stoy (mstoy) said: Ah, the joy of macros... (had no idea what was going on, therefore posted it here). Thanks everyone for the very quick feedback on this, the 2.2.3-SNAP1 release works as expected.