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

Add reflect TypeRepr.dealiasKeepOpaques #18583

Merged
merged 1 commit into from
Oct 23, 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
1 change: 1 addition & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def widenTermRefByName: TypeRepr = self.widenTermRefExpr
def widenByName: TypeRepr = self.widenExpr
def dealias: TypeRepr = self.dealias
def dealiasKeepOpaques: TypeRepr = self.dealiasKeepOpaques
def simplified: TypeRepr = self.simplified
def classSymbol: Option[Symbol] =
if self.classSymbol.exists then Some(self.classSymbol.asClass)
Expand Down
3 changes: 3 additions & 0 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
/** Follow aliases, annotated types until type is no longer alias type, annotated type. */
def dealias: TypeRepr

/** Follow non-opaque aliases, annotated types until type is no longer alias type, annotated type. */
def dealiasKeepOpaques: TypeRepr

/** A simplified version of this type which is equivalent wrt =:= to this type.
* Reduces typerefs, applied match types, and and or types.
*/
Expand Down
1 change: 1 addition & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object MiMaFilters {
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule.ValOrDefDefMethods"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#defnModule.FunctionClass"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#defnModule.PolyFunctionClass"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.dealiasKeepOpaques"),
)
val TastyCore: Seq[ProblemFilter] = Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyFormat.EXPLICITtpt"),
Expand Down
10 changes: 10 additions & 0 deletions tests/run-macros/tasty-dealiasKeepOpaques.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
java.lang.String
java.lang.String
scala.collection.immutable.List[Test_2$package.A]
scala.collection.immutable.List[scala.Int]
Test_2$package.OA
Test_2$package.OB
Test_2$package.OC[scala.Int]
Test_2$package.OA
Test_2$package.OB
Test_2$package.OC[scala.Int]
8 changes: 8 additions & 0 deletions tests/run-macros/tasty-dealiasKeepOpaques/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted.*

inline def dealiasKeepOpaques[T]: String = ${ impl[T] }

def impl[T: Type](using Quotes) : Expr[String] = {
import quotes.reflect.*
Expr(TypeRepr.of[T].dealiasKeepOpaques.show)
}
29 changes: 29 additions & 0 deletions tests/run-macros/tasty-dealiasKeepOpaques/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type A = String
type B = List[A]
type C[X] = List[X]

opaque type OA = String
object OA:
def test = println(dealiasKeepOpaques[OA])

opaque type OB = List[A]
object OB:
def test = println(dealiasKeepOpaques[OB])

opaque type OC[X] = List[X]
object OC:
def test = println(dealiasKeepOpaques[OC[Int]])


@main def Test: Unit = {
println(dealiasKeepOpaques[String])
println(dealiasKeepOpaques[A])
println(dealiasKeepOpaques[B])
println(dealiasKeepOpaques[C[Int]])
println(dealiasKeepOpaques[OA])
println(dealiasKeepOpaques[OB])
println(dealiasKeepOpaques[OC[Int]])
OA.test
OB.test
OC.test
}