Skip to content

Commit

Permalink
Merge pull request #13302 from dotty-staging/remove-proto-from-typed-…
Browse files Browse the repository at this point in the history
…unapply
  • Loading branch information
dwijnand authored Aug 27, 2021
2 parents 7a6cabe + aeb3db1 commit 094a3c5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def Alternative(trees: List[Tree])(using Context): Alternative =
ta.assignType(untpd.Alternative(trees), trees)

def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree], proto: Type)(using Context): UnApply = {
def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree])(using Context): UnApply = {
assert(fun.isInstanceOf[RefTree] || fun.isInstanceOf[GenericApply])
ta.assignType(untpd.UnApply(fun, implicits, patterns), proto)
ta.assignType(untpd.UnApply(fun, implicits, patterns), defn.NothingType)
}

def ValDef(sym: TermSymbol, rhs: LazyTree = EmptyTree)(using Context): ValDef =
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ class TreePickler(pickler: TastyPickler) {
writeByte(IMPLICITarg)
pickleTree(implicitArg)
}
pickleType(tree.tpe)
// TODO write a dummy type that takes less space?
pickleType(tree.tpe) // IGNORED // TODO remove when we can break TASTy compat.
patterns.foreach(pickleTree)
}
case tree: ValDef =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1248,9 +1248,9 @@ class TreeUnpickler(reader: TastyReader,
readByte()
readTerm()
}
val patType = readType()
val patType = readType() // IGNORED // TODO remove when we can break TASTy compat.
val argPats = until(end)(readTerm())
UnApply(fn, implicitArgs, argPats, patType)
UnApply(fn, implicitArgs, argPats)
case REFINEDtpt =>
val refineCls = symAtAddr.getOrElse(start,
newRefinedClassSymbol(coordAt(start))).asClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
case UNAPPLYtree =>
val fun = readTreeRef()
val args = until(end, () => readTreeRef())
UnApply(fun, Nil, args, defn.AnyType) // !!! this is wrong in general
UnApply(fun, Nil, args)

case ARRAYVALUEtree =>
val elemtpt = readTreeRef()
Expand Down
17 changes: 11 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ trait QuotesAndSplices {
* },
* true, // If there is at least one type splice. Used to instantiate the context with or without GADT constraints
* x$2 // tasty.Reflection instance
* ) => ...
* ): Expr[S & List[t] @unchecked] => ...
* ```
*
* For a scrutinee of type `S`, the `: Expr[S & List[t] @unchecked]` tells the pattern that if the pattern matched the bound
* scrutinee `x @ '{..}` is of type `Expr[S & List[t] @unchecked]`.
*/
private def typedQuotePattern(tree: untpd.Quote, pt: Type, qctx: Tree)(using Context): Tree = {
if tree.quoted.isTerm && !pt.derivesFrom(defn.QuotedExprClass) then
Expand Down Expand Up @@ -469,10 +472,12 @@ trait QuotesAndSplices {
val matchModule = if tree.quoted.isTerm then defn.QuoteMatching_ExprMatch else defn.QuoteMatching_TypeMatch
val unapplyFun = qctx.asInstance(defn.QuoteMatchingClass.typeRef).select(matchModule).select(nme.unapply)

UnApply(
fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
implicits = quotedPattern :: Nil,
patterns = splicePat :: Nil,
proto = quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt))
Typed(
UnApply(
fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
implicits = quotedPattern :: Nil,
patterns = splicePat :: Nil),
TypeTree(quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt))
).annotated(New(defn.UncheckedAnnot.typeRef, Nil))
}
}
2 changes: 1 addition & 1 deletion compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

object Unapply extends UnapplyModule:
def apply(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply =
withDefaultPos(tpd.UnApply(fun, implicits, patterns, dotc.core.Symbols.defn.NothingType))
withDefaultPos(tpd.UnApply(fun, implicits, patterns))
def copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply =
withDefaultPos(tpd.cpy.UnApply(original)(fun, implicits, patterns))
def unapply(x: Unapply): (Term, List[Term], List[Tree]) =
Expand Down

0 comments on commit 094a3c5

Please sign in to comment.