Skip to content

Add SkolemType in metaprogramming #13579

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,18 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def unapply(x: NoPrefix): true = true
end NoPrefix

type SkolemType = dotc.core.Types.SkolemType

object SkolemTypeTypeTest extends TypeTest[TypeRepr, SkolemType]:
def unapply(x: TypeRepr): Option[SkolemType & x.type] = x match
case tpe: (Types.SkolemType & x.type) => Some(tpe)
case _ => None
end SkolemTypeTypeTest

object SkolemType extends SkolemTypeModule:
def unapply(x : SkolemType) : Some[TypeRepr] = Some(x.info)
end SkolemType

type Constant = dotc.core.Constants.Constant

object Constant extends ConstantModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ object Extractors {
this += "NoPrefix()"
case MatchCase(pat, rhs) =>
this += "MatchCase(" += pat += ", " += rhs += ")"
case SkolemType(info) =>
this += "SkolemType(" += info += ")"
}

def visitSignature(sig: Signature): this.type = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,11 @@ object SourceCode {
this += " => "
printType(rhs)

case SkolemType(info) =>
this += "$skolem["
printType(info)
this += "]"

case _ =>
throw new MatchError(tpe.show(using Printer.TypeReprStructure))
}
Expand Down
16 changes: 16 additions & 0 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3163,6 +3163,22 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def unapply(x: NoPrefix): true
}

// ----- SkolemType -----------------------------------------------

/** SkolemType for a type selection */
type SkolemType <: TypeRepr

/** `TypeTest` that allows testing at runtime in a pattern match if a `TypeRepr` is a `SkolemType` */
given SkolemTypeTypeTest: TypeTest[TypeRepr, SkolemType]

/** Module object of `type SkolemType` */
val SkolemType: SkolemTypeModule

/** Methods of the module object `val SkolemType` */
trait SkolemTypeModule { this: SkolemType.type =>
def unapply(x: SkolemType): Some[TypeRepr]
}

///////////////
// CONSTANTS //
///////////////
Expand Down