Skip to content

Commit 094a3c5

Browse files
authored
Merge pull request #13302 from dotty-staging/remove-proto-from-typed-unapply
2 parents 7a6cabe + aeb3db1 commit 094a3c5

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
197197
def Alternative(trees: List[Tree])(using Context): Alternative =
198198
ta.assignType(untpd.Alternative(trees), trees)
199199

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

205205
def ValDef(sym: TermSymbol, rhs: LazyTree = EmptyTree)(using Context): ValDef =

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ class TreePickler(pickler: TastyPickler) {
538538
writeByte(IMPLICITarg)
539539
pickleTree(implicitArg)
540540
}
541-
pickleType(tree.tpe)
541+
// TODO write a dummy type that takes less space?
542+
pickleType(tree.tpe) // IGNORED // TODO remove when we can break TASTy compat.
542543
patterns.foreach(pickleTree)
543544
}
544545
case tree: ValDef =>

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,9 +1248,9 @@ class TreeUnpickler(reader: TastyReader,
12481248
readByte()
12491249
readTerm()
12501250
}
1251-
val patType = readType()
1251+
val patType = readType() // IGNORED // TODO remove when we can break TASTy compat.
12521252
val argPats = until(end)(readTerm())
1253-
UnApply(fn, implicitArgs, argPats, patType)
1253+
UnApply(fn, implicitArgs, argPats)
12541254
case REFINEDtpt =>
12551255
val refineCls = symAtAddr.getOrElse(start,
12561256
newRefinedClassSymbol(coordAt(start))).asClass

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
11751175
case UNAPPLYtree =>
11761176
val fun = readTreeRef()
11771177
val args = until(end, () => readTreeRef())
1178-
UnApply(fun, Nil, args, defn.AnyType) // !!! this is wrong in general
1178+
UnApply(fun, Nil, args)
11791179

11801180
case ARRAYVALUEtree =>
11811181
val elemtpt = readTreeRef()

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,11 @@ trait QuotesAndSplices {
400400
* },
401401
* true, // If there is at least one type splice. Used to instantiate the context with or without GADT constraints
402402
* x$2 // tasty.Reflection instance
403-
* ) => ...
403+
* ): Expr[S & List[t] @unchecked] => ...
404404
* ```
405+
*
406+
* For a scrutinee of type `S`, the `: Expr[S & List[t] @unchecked]` tells the pattern that if the pattern matched the bound
407+
* scrutinee `x @ '{..}` is of type `Expr[S & List[t] @unchecked]`.
405408
*/
406409
private def typedQuotePattern(tree: untpd.Quote, pt: Type, qctx: Tree)(using Context): Tree = {
407410
if tree.quoted.isTerm && !pt.derivesFrom(defn.QuotedExprClass) then
@@ -469,10 +472,12 @@ trait QuotesAndSplices {
469472
val matchModule = if tree.quoted.isTerm then defn.QuoteMatching_ExprMatch else defn.QuoteMatching_TypeMatch
470473
val unapplyFun = qctx.asInstance(defn.QuoteMatchingClass.typeRef).select(matchModule).select(nme.unapply)
471474

472-
UnApply(
473-
fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
474-
implicits = quotedPattern :: Nil,
475-
patterns = splicePat :: Nil,
476-
proto = quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt))
475+
Typed(
476+
UnApply(
477+
fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
478+
implicits = quotedPattern :: Nil,
479+
patterns = splicePat :: Nil),
480+
TypeTree(quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt))
481+
).annotated(New(defn.UncheckedAnnot.typeRef, Nil))
477482
}
478483
}

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
14841484

14851485
object Unapply extends UnapplyModule:
14861486
def apply(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply =
1487-
withDefaultPos(tpd.UnApply(fun, implicits, patterns, dotc.core.Symbols.defn.NothingType))
1487+
withDefaultPos(tpd.UnApply(fun, implicits, patterns))
14881488
def copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply =
14891489
withDefaultPos(tpd.cpy.UnApply(original)(fun, implicits, patterns))
14901490
def unapply(x: Unapply): (Term, List[Term], List[Tree]) =

0 commit comments

Comments
 (0)