Skip to content

Fix #7048: Heal phase inconsistent path dependent types #7117

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 1 commit into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
// Replace it with a properly encoded type splice. This is the normal for expected for type splices.
tp.prefix.select(tpnme.splice)
case tp: NamedType =>
checkSymLevel(tp.symbol, tp, pos) match {
if (tp.prefix.isInstanceOf[TermRef] && tp.prefix.isStable) tp
else checkSymLevel(tp.symbol, tp, pos) match {
case Some(tpRef) => tpRef.tpe
case _ =>
if (tp.symbol.is(Param)) tp
Expand Down
11 changes: 11 additions & 0 deletions tests/neg/i5954b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
abstract class MatcherFactory1[A] {
class AndNotWord
}

object MatcherFactory1 {
import scala.quoted._

def impl[T](self: Expr[MatcherFactory1[T]#AndNotWord]) given QuoteContext =
'{ val a: Any = $self } // error: access to type T from wrong staging level

}
11 changes: 11 additions & 0 deletions tests/neg/i5954c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
abstract class MatcherFactory1 {
class AndNotWord[A]
}

object MatcherFactory1 {
import scala.quoted._

def impl[T](self: Expr[MatcherFactory1#AndNotWord[T]]) given QuoteContext =
'{ val a: Any = $self } // error: access to type T from wrong staging level

}
15 changes: 15 additions & 0 deletions tests/pos/i5954b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
abstract class MatcherFactory1 {
class AndNotWord[A]
}

object MatcherFactory1 {
import scala.quoted._

def impl(self: Expr[MatcherFactory1#AndNotWord[Int]]) given QuoteContext =
'{ val a: Any = $self }


def impl[T: Type](self: Expr[MatcherFactory1#AndNotWord[T]]) given QuoteContext =
'{ val a: Any = $self }

}
15 changes: 15 additions & 0 deletions tests/pos/i5954c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
abstract class MatcherFactory1[A] {
class AndNotWord
}

object MatcherFactory1 {
import scala.quoted._

def impl(self: Expr[MatcherFactory1[Int]#AndNotWord]) given QuoteContext =
'{ val a: Any = $self }


def impl[T: Type](self: Expr[MatcherFactory1[T]#AndNotWord]) given QuoteContext =
'{ val a: Any = $self }

}
15 changes: 15 additions & 0 deletions tests/pos/i5954d.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
abstract class MatcherFactory1 {
type AndNotWord
}

object MatcherFactory1 {
import scala.quoted._

def impl(self: Expr[MatcherFactory1#AndNotWord]) given QuoteContext =
'{ val a: Any = $self }


def impl2[T: Type](a: MatcherFactory1)(self: Expr[T])(implicit ev: T =:= a.AndNotWord, qctx: QuoteContext) =
'{ val a: Any = $self }

}
13 changes: 13 additions & 0 deletions tests/pos/i7048.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted._

trait IsExpr[T] {
type Underlying
def expr: Expr[Underlying]
}

def f(x: Any): String = x.toString

def g[T] given (e: IsExpr[T], tu: Type[e.Underlying]): given QuoteContext => Expr[String] = {
val underlying: Expr[e.Underlying] = e.expr
'{f($underlying)}
}
12 changes: 12 additions & 0 deletions tests/pos/i7048b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.quoted._

trait IsExpr {
type Underlying
}

val foo: IsExpr = ???

def g() given QuoteContext: Unit = {
val a = '[foo.Underlying]
()
}
13 changes: 13 additions & 0 deletions tests/pos/i7048c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted._

trait IsExpr {
type Underlying
}

val foo: IsExpr = ???

def g(e: IsExpr) given (tu: Type[e.Underlying]): Unit = ???

def mcrImpl given QuoteContext: Unit = {
g(foo)
}
13 changes: 13 additions & 0 deletions tests/pos/i7048d.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted._

trait IsExpr {
class Underlying
}

val foo: IsExpr = ???

def g(e: IsExpr) given (tu: Type[e.Underlying]): Unit = ???

def mcrImpl given QuoteContext: Unit = {
g(foo)
}
24 changes: 24 additions & 0 deletions tests/run-macros/i7048/Lib_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import scala.quoted._

trait IsExpr[T] {
type Underlying
def toExpr(x: T): Expr[Underlying]
}

given [U] as IsExpr[Expr[U]] = new IsExpr[Expr[U]] {
type Underlying = U
def toExpr(x: Expr[U]): Expr[U] = x
}

def f(x: Any): String = x.toString

def g[T](x: T) given (e: IsExpr[T], tu: Type[e.Underlying]): given QuoteContext => Expr[String] = {
val underlying: Expr[e.Underlying] = e.toExpr(x)
'{f($underlying)}
}

inline def mcr(): Any = ${mcrImpl}
def mcrImpl given QuoteContext: Expr[Any] = {
val x = '{1}
g(x)
}
5 changes: 5 additions & 0 deletions tests/run-macros/i7048/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test {
def main(args: Array[String]): Unit = {
mcr()
}
}