Skip to content

Fix #6588: synthesis of Type[T] should mapOver the type T #6589

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
wants to merge 2 commits into from

Conversation

liufengyun
Copy link
Contributor

Fix #6588: synthesis of Type[T] should mapOver the type T

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Looks good except for the inInlineMethod test.

def apply(t: Type) = t match {
case t @ TypeRef(NoPrefix, _) =>
def apply(t: Type) = t.dealias match {
case t @ TypeRef(NoPrefix, _) if !ctx.inInlineMethod =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not understand the qualification !ctx.inInlineMethod. This looks fishy where it is. The other synthesized arguments do not depend on this test, so why would quoted.Type be different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case below in the outer match, we have the following logic:

https://github.com/lampepfl/dotty/blob/c165638cb46e498156bffcb5ad4ad4775d11bf35/compiler/src/dotty/tools/dotc/typer/Implicits.scala#L701-L702

I conjecture the motivation is that in inline methods, type parameters are treated as constants so that they are not restricted by phase consistency law, just like inline term parameters. /cc : @nicolasstucki

More concretely, without the test, the following test case i4514.scala fail:

object Foo {
  inline def foo[X](x: X): Unit = ${fooImpl('x)}
  def fooImpl[X: quoted.Type](x: X): quoted.Expr[Unit] = '{}
}

The implicit search first looks for Type[Expr[X]], the mapOver will reach X, and the implicit search for Type[X] fails.

@nicolasstucki nicolasstucki self-requested a review May 31, 2019 13:20
inferImplicit(defn.QuotedTypeType.appliedTo(t), EmptyTree, span) match {
case SearchSuccess(tag, _, _) if tag.tpe.isStable =>
tag.tpe.select(defn.QuotedType_splice)
case _ =>
ok = false
t
}
case _ => t
case tp => mapOver(tp)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the motivation to mapOver? This is suspicious. Is it to dealias further term as you have in the tests? Mapping over may also trigger another implicit search for parts of the type which should only be done in the PCP checks.

Copy link
Contributor Author

@liufengyun liufengyun May 31, 2019

Choose a reason for hiding this comment

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

If we do not mapOver, for the following code:

import scala.quoted._

inline def foo[T:Type]: Int = 10
def main = {
  type S = Int
  type V = List[S]
  foo[V]
}

It will generate an evidence in staging:

        type V = List[S]
        {
          val evidence$1: quoted.Type[List[S]] =
            '[List[quoted.Type[Int]#$splice]]
          10:Int
        }

The code will then crash ReifyQuotes.scala:153, as it assumes the prefixes of evidences are TermRefs.

@nicolasstucki
Copy link
Contributor

@liufengyun as we discussed I replaced this PR with #6599 which contains an improved fix and an additional assertion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler failed to synthesize Type[T] for local type alias T
3 participants