-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow ill-staged references to local classes (#19869)
Fixes #19856
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import scala.quoted.* | ||
|
||
def test(using Quotes): Any = | ||
class Foo { | ||
class IdxWrapper | ||
def foo(using Type[IdxWrapper]): Expr[Any] = | ||
'{ new IdxWrapper } // error | ||
} | ||
() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import scala.deriving.Mirror | ||
import scala.quoted.{Expr, Quotes, Type} | ||
|
||
trait macroTest[A] { | ||
type ElemTop <: A | ||
type Index[_] | ||
|
||
case class IdxWrapper[X](idx: Index[X]) | ||
|
||
def indexOf[X <: ElemTop: Type](x: Expr[X]): Expr[Index[X]] | ||
|
||
def indexOfA(a: Expr[A]): Expr[IdxWrapper[_ <: ElemTop]] | ||
} | ||
object macroTest { | ||
|
||
def derivedImpl[A: Type, ElemTypes <: Tuple: Type, Label <: String: Type, Labels <: Tuple: Type]( | ||
using m: Expr[ | ||
Mirror.SumOf[A] { | ||
type MirroredElemTypes = ElemTypes | ||
type MirroredLabel = Label | ||
type MirroredElemLabels = Labels | ||
} | ||
], | ||
q: Quotes, | ||
): macroTest[A] = new macroTest[A]: | ||
override type Index[_] = Int | ||
|
||
override def indexOf[X <: ElemTop: Type](x: Expr[X]): Expr[Index[X]] = '{ $m.ordinal($x) } | ||
|
||
override def indexOfA(a: Expr[A]): Expr[IdxWrapper[_ <: ElemTop]] = | ||
given Type[IdxWrapper] = Type.of[IdxWrapper] // error | ||
given Type[ElemTop] = Type.of[ElemTop] // error | ||
'{ new IdxWrapper(${ indexOf(a.asInstanceOf[Expr[ElemTop]]) }) } // error // error | ||
} |