Skip to content

Commit ba0ac5e

Browse files
Merge pull request #13421 from dotty-staging/fix-#13405
Revert "Remove unnecessary type from UnApply"
2 parents b014ffe + 1d7ef8b commit ba0ac5e

File tree

9 files changed

+27
-19
lines changed

9 files changed

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

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,7 @@ class TreePickler(pickler: TastyPickler) {
538538
writeByte(IMPLICITarg)
539539
pickleTree(implicitArg)
540540
}
541-
// TODO write a dummy type that takes less space?
542-
pickleType(tree.tpe) // IGNORED // TODO remove when we can break TASTy compat.
541+
pickleType(tree.tpe)
543542
patterns.foreach(pickleTree)
544543
}
545544
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
@@ -1246,9 +1246,9 @@ class TreeUnpickler(reader: TastyReader,
12461246
readByte()
12471247
readTerm()
12481248
}
1249-
val patType = readType() // IGNORED // TODO remove when we can break TASTy compat.
1249+
val patType = readType()
12501250
val argPats = until(end)(readTerm())
1251-
UnApply(fn, implicitArgs, argPats)
1251+
UnApply(fn, implicitArgs, argPats, patType)
12521252
case REFINEDtpt =>
12531253
val refineCls = symAtAddr.getOrElse(start,
12541254
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)
1178+
UnApply(fun, Nil, args, defn.AnyType) // !!! this is wrong in general
11791179

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

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,8 @@ 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-
* ): Expr[S & List[t] @unchecked] => ...
403+
* ) => ...
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]`.
408405
*/
409406
private def typedQuotePattern(tree: untpd.Quote, pt: Type, qctx: Tree)(using Context): Tree = {
410407
if tree.quoted.isTerm && !pt.derivesFrom(defn.QuotedExprClass) then
@@ -472,12 +469,10 @@ trait QuotesAndSplices {
472469
val matchModule = if tree.quoted.isTerm then defn.QuoteMatching_ExprMatch else defn.QuoteMatching_TypeMatch
473470
val unapplyFun = qctx.asInstance(defn.QuoteMatchingClass.typeRef).select(matchModule).select(nme.unapply)
474471

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))
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))
482477
}
483478
}

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))
1487+
withDefaultPos(tpd.UnApply(fun, implicits, patterns, dotc.core.Symbols.defn.NothingType))
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]) =

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class BootstrappedOnlyCompilationTests {
2929
compileFilesInDir("tests/pos-custom-args/semanticdb", defaultOptions.and("-Xsemanticdb")),
3030
compileDir("tests/pos-special/i7592", defaultOptions.and("-Yretain-trees")),
3131
compileDir("tests/pos-special/i11331.1", defaultOptions),
32+
compileDir("tests/pos-custom-args/i13405", defaultOptions.and("-Xfatal-warnings")),
3233
).checkCompile()
3334
}
3435

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted.*
2+
3+
sealed class Foo()
4+
inline def hh(): Unit = ${ interpMacro() }
5+
6+
private def interpMacro()(using Quotes): Expr[Unit] =
7+
import quotes.reflect.*
8+
'{
9+
val res: Either[String, (Foo, Foo)] =
10+
Right((new Foo, new Foo))
11+
val (a, b) = res.toOption.get
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@main def main: Unit = hh()

0 commit comments

Comments
 (0)