Skip to content

Explicitly search the given QuoteContext of the quotes #8262

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
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
18 changes: 10 additions & 8 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ trait QuotesAndSplices {
ctx.warning("Canceled splice directly inside a quote. '[ ${ XYZ } ] is equivalent to XYZ.", tree.sourcePos)
case _ =>
}
val qctx = inferImplicitArg(defn.QuoteContextClass.typeRef, tree.span)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inferring implicit args for implicit function types complicate existing typing rules. It's better to avoid the special case and only use it as a last resort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be required in #8281

if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType])
ctx.error(missingArgMsg(qctx, defn.QuoteContextClass.typeRef, ""), ctx.source.atSpan(tree.span))
val tree1 =
if (ctx.mode.is(Mode.Pattern) && level == 0) typedQuotePattern(tree, pt)
else if (tree.quoted.isType) typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuote.termRef), tree.quoted :: Nil), pt)(quoteContext)
else typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuote.termRef), tree.quoted), pt)(quoteContext)
if ctx.mode.is(Mode.Pattern) && level == 0 then
typedQuotePattern(tree, pt, qctx)
else if (tree.quoted.isType)
typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuote.termRef), tree.quoted :: Nil), pt)(quoteContext)
else
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuote.termRef), tree.quoted), pt)(quoteContext).select(nme.apply).appliedTo(qctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this line, as previously, we don't need to .select(nme.apply).appliedTo(qctx), and it worked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we were letting typer find and apply it. But as we know it we can just add it explicitly. In the previous case, it did not find the implicit it emitted an error mentioning CompileTime.quotedExpr in some situations.

tree1.withSpan(tree.span)
}

Expand Down Expand Up @@ -326,11 +332,7 @@ trait QuotesAndSplices {
* ) => ...
* ```
*/
private def typedQuotePattern(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = {
val qctx = inferImplicitArg(defn.QuoteContextClass.typeRef, tree.span)
if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType])
ctx.error(missingArgMsg(qctx, defn.QuoteContextClass.typeRef, ""), ctx.source.atSpan(tree.span))

private def typedQuotePattern(tree: untpd.Quote, pt: Type, qctx: Tree)(implicit ctx: Context): Tree = {
val quoted = tree.quoted
val exprPt = pt.baseType(if quoted.isType then defn.QuotedTypeClass else defn.QuotedExprClass)
val quotedPt = exprPt.argInfos.headOption match {
Expand Down