Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IncOptions.useOptimizedSealed not working for Scala 2.13 #1278

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
}

}