Skip to content

Commit

Permalink
INCOMPLETE, start working on #101
Browse files Browse the repository at this point in the history
  • Loading branch information
tribbloid committed Aug 31, 2023
1 parent 34f848b commit 7b14035
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 87 deletions.
21 changes: 11 additions & 10 deletions core/src/main/scala-2.13.7+/latest/splain/ImplicitsExtension.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package splain

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.tools.nsc.typechecker

trait ImplicitsExtension extends typechecker.Implicits {
Expand All @@ -22,6 +23,14 @@ trait ImplicitsExtension extends typechecker.Implicits {

@volatile protected var _currentGlobalHistory: GlobalHistory = _

def currentGlobal: GlobalHistory = Option(_currentGlobalHistory).getOrElse {
ImplicitHistory.synchronized {
val result = GlobalHistory()
_currentGlobalHistory = result
result
}
}

case class GlobalHistory() {

val byPosition = mutable.HashMap.empty[PositionIndex, LocalHistory]
Expand All @@ -31,7 +40,7 @@ trait ImplicitsExtension extends typechecker.Implicits {

object DivergingImplicitErrors {

val errors = mutable.ArrayBuffer.empty[DivergentImplicitTypeError]
val errors: ArrayBuffer[DivergentImplicitTypeError] = mutable.ArrayBuffer.empty[DivergentImplicitTypeError]

def push(v: DivergentImplicitTypeError): Unit = {
errors.addOne(v)
Expand All @@ -54,22 +63,14 @@ trait ImplicitsExtension extends typechecker.Implicits {
result
}

val logs = mutable.ArrayBuffer.empty[String]
val logs: ArrayBuffer[String] = mutable.ArrayBuffer.empty[String]
// unused messages & comments will be displayed at the end of the implicit error
}
}

case class PositionIndex(
pos: Position
) {}

def currentGlobal: GlobalHistory = Option(_currentGlobalHistory).getOrElse {
ImplicitHistory.synchronized {
val result = GlobalHistory()
_currentGlobalHistory = result
result
}
}
}

override def inferImplicit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait SplainFormattersExtension extends SplainFormatters {
None
case RefinedType(types, scope) =>
if (scope.isEmpty) {
val subtypes = types.map(v => dealiasIfNecessary(v)).flatMap {
val subtypes = types.map(v => dealias(v)).flatMap {
case Refined(types, _) =>
types
case tpe =>
Expand Down
Loading

0 comments on commit 7b14035

Please sign in to comment.