-
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 local term references in staged types (#16362)
- Loading branch information
Showing
4 changed files
with
51 additions
and
2 deletions.
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,6 @@ | ||
import scala.quoted.* | ||
|
||
def m(using Quotes): Expr[Option[_]] = | ||
val s = 3 | ||
type st = s.type | ||
'{ Some(${ Expr(s) }: st) } // 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,35 @@ | ||
//> using scala "3.2.1" | ||
import scala.quoted.Expr | ||
import scala.quoted.Type | ||
import scala.quoted.quotes | ||
import scala.quoted.Quotes | ||
|
||
object macros { | ||
|
||
inline transparent def mkNames[A]: List[Any] = ${ mkNamesImpl[A] } | ||
|
||
def mkNamesImpl[A: Type](using Quotes): Expr[List[Any]] = { | ||
import quotes.reflect._ | ||
|
||
val fieldNames = TypeRepr.of[A].typeSymbol.declaredFields.map(_.name) | ||
|
||
val types = fieldNames | ||
.map { f => | ||
val t1 = ConstantType(StringConstant(f)) | ||
t1.asType match { | ||
case '[t1Type] => TypeRepr.of[(t1Type, "aa")] | ||
} | ||
} | ||
.reduceLeft[TypeRepr](OrType(_, _)) | ||
|
||
types.asType match { | ||
case '[ttt] => | ||
Expr.ofList[ttt]( | ||
fieldNames.map { v => | ||
Expr[(v.type, "aa")](v -> "aa").asExprOf[ttt] // 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,4 @@ | ||
import scala.quoted._ | ||
def test(v: String)(using Quotes): Any = | ||
Type.of : Type[v.type] // error | ||
Type.of[v.type] // error |