Skip to content

Commit

Permalink
workaround scala-reflect non-threadsafe <:< operation that upstream W…
Browse files Browse the repository at this point in the history
…ONTFIX scala/bug#10766
  • Loading branch information
neko-kai committed May 30, 2019
1 parent 245efd7 commit b04a079
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.pshirshov.izumi.fundamentals.reflection

import com.github.pshirshov.izumi.fundamentals.reflection.ReflectionUtil._
import com.github.pshirshov.izumi.fundamentals.reflection.SafeType0.globalSubtypeCheckLock

import scala.reflect.runtime.{universe => ru}

Expand Down Expand Up @@ -73,23 +72,21 @@ class SafeType0[U <: SingletonUniverse](
}
}

// <:< is not thread-safe and upstream refuses to fix that.
// /~https://github.com/scala/bug/issues/10766
final def <:<(that: SafeType0[U]): Boolean =
globalSubtypeCheckLock.synchronized {
SafeType0.synchronized {
dealiased <:< that.dealiased || freeTermPrefixTypeSuffixHeuristicEq(_ <:< _, dealiased, that.dealiased)
}

final def weak_<:<(that: SafeType0[U]): Boolean =
globalSubtypeCheckLock.synchronized {
SafeType0.synchronized {
(dealiased weak_<:< that.dealiased) || freeTermPrefixTypeSuffixHeuristicEq(_ weak_<:< _, dealiased, that.dealiased)
}
}

object SafeType0 {

// <:< is not thread-safe and upstream refuses to fix that.
// /~https://github.com/scala/bug/issues/10766
private[SafeType0] object globalSubtypeCheckLock

def apply[U <: SingletonUniverse](u: U, tpe: U#Type): SafeType0[U] = new SafeType0[U](u, tpe)

def apply(tpe: ru.Type): SafeType0[ru.type] = new SafeType0[ru.type](ru, tpe)
Expand Down

0 comments on commit b04a079

Please sign in to comment.