Skip to content

Commit e9808a9

Browse files
committed
Add quoted pattern type variable expected type test
1 parent 05b26be commit e9808a9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/neg-macros/i22616b.check

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- [E007] Type Mismatch Error: tests/neg-macros/i22616b.scala:17:18 ----------------------------------------------------
2+
17 | case '{ Foo($y: t) } => // error
3+
| ^^^^^
4+
| Found: t
5+
| Required: String
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E006] Not Found Error: tests/neg-macros/i22616b.scala:18:19 --------------------------------------------------------
9+
18 | '{type S = t; ()} // error
10+
| ^
11+
| Not found: type t
12+
|
13+
| longer explanation available when compiling with `-explain`

tests/neg-macros/i22616b.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This test illustrates a current limitation of quoted pattern type variables,
2+
// which has been discussed in https://github.com/scala/scala3/issues/22616#issuecomment-3012534064:
3+
// These type variables do not have bound in general (see `typedQuotedTypeVar`),
4+
// so they might not conform to the expected type. Here, `t` does not conform
5+
// to `String`.
6+
7+
import scala.quoted.{FromExpr, Expr, Quotes}
8+
9+
case class Foo(x: String)
10+
11+
object Macro:
12+
inline def myMacro(): Unit =
13+
${ myMacroImpl('{Foo("hello")}) }
14+
15+
def myMacroImpl(x: Expr[Foo])(using Quotes): Expr[Unit] =
16+
x match
17+
case '{ Foo($y: t) } => // error
18+
'{type S = t; ()} // error
19+
case _ =>
20+
println("not a foo")
21+
22+
'{()}

0 commit comments

Comments
 (0)