Skip to content

Commit

Permalink
Merge pull request #37 from AVSystem/scala-2.13.14-hash-code-fix
Browse files Browse the repository at this point in the history
Fixed infinite background compilation in scala 2.13.14
  • Loading branch information
ddworak committed Jun 5, 2024
2 parents 89a5816 + 2a9e55c commit 8e745b3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ import scala.reflect.internal.util.BatchSourceFile
* Author: ghik
*/
class ScexSourceFile(name: String, contents: String, val shared: Boolean)
extends BatchSourceFile(name, contents)
extends BatchSourceFile(name, contents) {

override def equals(that: Any): Boolean = that match {
case that: ScexSourceFile => file.path == that.file.path && start == that.start
case _ => super.equals(that)
}

override def hashCode: Int = file.path.## + start.##

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.avsystem.scex.compiler

import com.avsystem.scex.compiler.presentation.ScexPresentationCompiler
import com.avsystem.scex.japi.{JavaScexCompiler, ScalaTypeTokens}
import com.avsystem.scex.util.{PredefinedAccessSpecs, SimpleContext}
import org.scalatest.funsuite.AnyFunSuite

class OufOfDateUnitScexCompilerTest extends AnyFunSuite with CompilationTest {

override protected def createCompiler: noCacheCompiler.type = noCacheCompiler

object noCacheCompiler
extends ScexCompiler
with ScexPresentationCompiler
with JavaScexCompiler
with ClassfileReusingScexCompiler {

val settings = new ScexSettings
settings.classfileDirectory.value = "testClassfileCache"
}

/** *
* Purpose of this test it to compile same expression using same profile multiple times with disabled caching to force execution of backgroundCompile method
* backgroundCompile was infinitely executed with changes introduced by 2.13.13
*/
test("out of date compilation") {
val acl = PredefinedAccessSpecs.basicOperations
val profile = createProfile(acl)

def compileExpression(): Unit = {
compiler.buildExpression
.contextType(ScalaTypeTokens.create[SimpleContext[Unit]])
.resultType(classOf[String])
.expression(s""""value"""")
.template(false)
.profile(profile)
.get
}

compileExpression()
compileExpression()
}


}

0 comments on commit 8e745b3

Please sign in to comment.