-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -683,16 +683,16 @@ trait Implicits { self: Typer => | |
case arg :: Nil if !arg.typeSymbol.is(Param) => | ||
object bindFreeVars extends TypeMap { | ||
var ok = true | ||
def apply(t: Type) = t match { | ||
case t @ TypeRef(NoPrefix, _) => | ||
def apply(t: Type) = t.dealias match { | ||
case t @ TypeRef(NoPrefix, _) if !ctx.inInlineMethod => | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the motivation to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do not 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 type V = List[S]
{
val evidence$1: quoted.Type[List[S]] =
'[List[quoted.Type[Int]#$splice]]
10:Int
} The code will then crash |
||
} | ||
} | ||
val tag = bindFreeVars(arg) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import scala.quoted._ | ||
|
||
inline def foo[T:Type]: Int = 10 | ||
|
||
def main = { | ||
type S = Int | ||
foo[S] | ||
foo[Int] | ||
|
||
type T = Int => Int | ||
foo[T] | ||
foo[Int => Int] | ||
|
||
type U = List[Int] | ||
foo[U] | ||
foo[List[Int]] | ||
|
||
type N = List | ||
foo[N] | ||
foo[List] | ||
|
||
type V = List[S] | ||
foo[V] | ||
|
||
type B = V => T | ||
foo[B] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
(null: scala.Any).asInstanceOf[java.lang.Object] | ||
(null: scala.Any).asInstanceOf[scala.Predef.String] | ||
(null: scala.Any).asInstanceOf[java.lang.String] |
There was a problem hiding this comment.
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 wouldquoted.Type
be different?There was a problem hiding this comment.
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:The implicit search first looks for
Type[Expr[X]]
, themapOver
will reachX
, and the implicit search forType[X]
fails.