Skip to content

Fix #9812: Do not widen types during quote reification #9814

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

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 2 additions & 8 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,10 @@ class ReifyQuotes extends MacroTransform {
}

def pickleAsTasty() = {
val meth =
if (isType) ref(defn.Unpickler_unpickleType).appliedToType(originalTp)
else
val tpe =
if originalTp =:= defn.NilModule.termRef then originalTp // Workaround #4987
else originalTp.widen.dealias
ref(defn.Unpickler_unpickleExpr).appliedToType(tpe)
val meth = if isType then defn.Unpickler_unpickleType else defn.Unpickler_unpickleExpr
val pickledQuoteStrings = liftList(PickledQuotes.pickleQuote(body).map(x => Literal(Constant(x))), defn.StringType)
val splicesList = liftList(splices, defn.FunctionType(1).appliedTo(defn.SeqType.appliedTo(defn.AnyType), defn.AnyType))
meth.appliedTo(pickledQuoteStrings, splicesList)
ref(meth).appliedToType(originalTp).appliedTo(pickledQuoteStrings, splicesList)
}

def taggedType(sym: Symbol) = ref(defn.InternalQuotedTypeModule).select(sym.name.toTermName)
Expand Down
8 changes: 8 additions & 0 deletions tests/pos-macros/i9812.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// compile with -Ycheck:reifyQuotes -Ystop-after:reifyQuotes
import quoted._

sealed abstract class SomeEnum
object SomeEnum:
final val Foo = new SomeEnum {}

def quoteFoo: QuoteContext ?=> Expr[SomeEnum.Foo.type] = '{SomeEnum.Foo}