Skip to content

Commit

Permalink
Merge pull request #1278 from Friendseeker/optimized_seal_fix
Browse files Browse the repository at this point in the history
Fix IncOptions.useOptimizedSealed not working for Scala 2.13
  • Loading branch information
eed3si9n authored Nov 5, 2023
2 parents 87e9b7e + b32986f commit 72101b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
package inc

import org.scalatest.diagrams.Diagrams
import xsbti.UseScope

class ExtractUsedNamesSpecification
extends UnitSpec
Expand Down Expand Up @@ -223,7 +224,6 @@ class ExtractUsedNamesSpecification
}

// This doesn't work in 2.13.0-RC1
/*
it should "extract sealed classes scope" in {
val sealedClassName = "Sealed"
val sealedClass =
Expand All @@ -238,12 +238,12 @@ class ExtractUsedNamesSpecification
val (_, callback) = compileSrcs(List(List(sealedClass, in)))
val clientNames = callback.usedNamesAndScopes.filterKeys(!_.startsWith("base."))

val names: Set[String] = clientNames.flatMap {
val names = clientNames.flatMap {
case (_, usages) =>
usages.filter(_.scopes.contains(UseScope.PatMatTarget)).map(_.name)
}(collection.breakOut)
}

names
names.toSet
}

def classWithPatMatOfType(tpe: String) =
Expand All @@ -259,13 +259,15 @@ class ExtractUsedNamesSpecification

// findPatMatUsages(classWithPatMatOfType()) shouldEqual Set(sealedClassName)

Option is sealed
// Option is sealed
findPatMatUsages(classWithPatMatOfType(s"Option[$sealedClassName]")) shouldEqual Set(
sealedClassName,
"Option")
"Option"
)
// Seq and Set is not
findPatMatUsages(classWithPatMatOfType(s"Seq[Set[$sealedClassName]]")) shouldEqual Set(
sealedClassName)
sealedClassName
)

def inNestedCase(tpe: String) =
s"""package client
Expand Down Expand Up @@ -293,7 +295,6 @@ class ExtractUsedNamesSpecification
findPatMatUsages(notUsedInPatternMatch) shouldEqual Set()
()
}
*/

/**
* Standard names that appear in every compilation unit that has any class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType)

private def handleClassicTreeNode(tree: Tree): Unit = tree match {
// Register names from pattern match target type in PatMatTarget scope
case matchNode: Match =>
updateCurrentOwner()
PatMatDependencyTraverser.traverse(matchNode.selector.tpe)
case ValDef(mods, _, tpt, _) if mods.isCase && mods.isSynthetic =>
updateCurrentOwner()
PatMatDependencyTraverser.traverse(tpt.tpe)
Expand Down
11 changes: 5 additions & 6 deletions zinc/src/test/scala/sbt/inc/NameHashingCompilerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ class NameHashingCompilerSpec extends BaseCompilerSpec {
optimizedSealed = false
)

// TODO: potential under compilation on 2.13 https://github.com/sbt/zinc/issues/753
// testIncrementalCompilation(
// changes = Seq(Other -> addNewSealedChildren),
// transitiveChanges = Set(Other3, Other),
// optimizedSealed = true
// )
testIncrementalCompilation(
changes = Seq(Other -> addNewSealedChildren),
transitiveChanges = Set(Other3, Other),
optimizedSealed = true
)
}

}

0 comments on commit 72101b7

Please sign in to comment.