Skip to content

Commit 36b820f

Browse files
committed
Add tests with the experimental flag
1 parent ac6e1dd commit 36b820f

12 files changed

+73
-1
lines changed

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ trait QuotesAndSplices {
127127
*/
128128
val bounds = ctx.gadt.fullBounds(typedTypearg.symbol)
129129
if bounds != null && bounds != TypeBounds.empty then
130-
report.error("Type arguments to Open pattern are expected to have no bounds", typearg.srcPos)
130+
report.error("Implementation restriction: Type arguments to Open pattern are expected to have no bounds", typearg.srcPos)
131131
typedTypearg
132132
case arg =>
133133
report.error("Open pattern expected an identifier", arg.srcPos)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class CompilationTests {
153153
compileFilesInDir("tests/neg-custom-args/no-experimental", defaultOptions.and("-Yno-experimental")),
154154
compileFilesInDir("tests/neg-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking")),
155155
compileFilesInDir("tests/neg-custom-args/explain", defaultOptions.and("-explain")),
156+
compileFilesInDir("tests/neg-custom-args/quoted-pattern-poly", defaultOptions.and("-language:experimental.quotedPatternsWithPolymorphicFunctions")),
156157
compileFile("tests/neg-custom-args/avoid-warn-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
157158
compileFile("tests/neg-custom-args/i3246.scala", scala2CompatMode),
158159
compileFile("tests/neg-custom-args/overrideClass.scala", scala2CompatMode),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg-custom-args/quoted-pattern-poly/quoted-pattern-with-bounded-type-params.scala:10:50 ----------------
2+
10 | case '{ [A <: Int, B] => (x : A, y : A) => $b[A](x, y) : A } => // error
3+
| ^
4+
| Implementation restriction: Type arguments to Open pattern are expected to have no bounds
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Error: tests/neg-custom-args/quoted-pattern-poly/quoted-pattern-with-type-params.scala:5:32 -------------------------
2+
5 | case '{ [A] => (x : A) => $b[A] : (A => A) } => // error
3+
| ^^^^^
4+
| Implementation restriction: A higher-order pattern must carry value arguments
5+
-- Error: tests/neg-custom-args/quoted-pattern-poly/quoted-pattern-with-type-params.scala:7:33 -------------------------
6+
7 | case '{ [A] => (x : A) => $b(x) : (A => A) } => // error
7+
| ^
8+
| Type variables that this argument depends on are not captured in this hoas pattern
9+
-- Error: tests/neg-custom-args/quoted-pattern-poly/quoted-pattern-with-type-params.scala:9:26 -------------------------
10+
9 | case '{ (a:Int) => $b[Int](a) : String } => // error
11+
| ^^^
12+
| Type arguments of a hoas pattern needs to be defined inside the quoted pattern

tests/neg-macros/hoas-pattern-with-bounded-type-params.check

Whitespace-only changes.

tests/neg-macros/hoas-pattern-with-type-params.check

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Error: tests/neg-macros/quoted-pattern-with-bounded-type-params.scala:10:48 -----------------------------------------
2+
10 | case '{ [A <: Int, B] => (x : A, y : A) => $b[A](x, y) : A } => // error
3+
| ^
4+
| Type must be fully defined.
5+
| Consider annotating the splice using a type ascription:
6+
| (${b}: XYZ).
7+
-- [E006] Not Found Error: tests/neg-macros/quoted-pattern-with-bounded-type-params.scala:11:10 ------------------------
8+
11 | '{ $b[String]("truthy", "falsy") } // error
9+
| ^
10+
| Not found: b
11+
|
12+
| longer explanation available when compiling with `-explain`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Supporting hoas quote pattern with bounded type variable
3+
* is future todo.
4+
* Refer to: neg-custom-args/quoted-pattern-poly/quoted-pattern-with-bounded-type-params.scala
5+
*/
6+
7+
import scala.quoted.*
8+
9+
def test(body: Expr[Any])(using Quotes): Expr[String] =
10+
body match
11+
case '{ [A <: Int, B] => (x : A, y : A) => $b[A](x, y) : A } => // error
12+
'{ $b[String]("truthy", "falsy") } // error
13+
case _ => Expr("not matched")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Error: tests/neg-macros/quoted-pattern-with-type-params.scala:5:31 --------------------------------------------------
2+
5 | case '{ [A] => (x : A) => $b[A] : (A => A) } => // error
3+
| ^
4+
| Type must be fully defined.
5+
| Consider annotating the splice using a type ascription:
6+
| (${b}: XYZ).
7+
-- Error: tests/neg-macros/quoted-pattern-with-type-params.scala:7:33 --------------------------------------------------
8+
7 | case '{ [A] => (x : A) => $b(x) : (A => A) } => // error
9+
| ^
10+
| Type variables that this argument depends on are not captured in this hoas pattern
11+
-- Error: tests/neg-macros/quoted-pattern-with-type-params.scala:9:24 --------------------------------------------------
12+
9 | case '{ (a:Int) => $b[Int](a) : String } => // error
13+
| ^
14+
| Type must be fully defined.
15+
| Consider annotating the splice using a type ascription:
16+
| (${b}: XYZ).
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Refer to: neg-custom-args/quoted-pattern-poly/quoted-pattern-with-type-params.scala
3+
*/
4+
import scala.quoted.*
5+
6+
def test(body: Expr[Any])(using Quotes): Expr[String] =
7+
body match
8+
case '{ [A] => (x : A) => $b[A] : (A => A) } => // error
9+
Expr("A higher-order pattern must carry value params")
10+
case '{ [A] => (x : A) => $b(x) : (A => A) } => // error
11+
Expr("`A` should be in type arguments because `x` depends on it")
12+
case '{ (a:Int) => $b[Int](a) : String } => // error
13+
Expr("Type params of a hoas pattern should be introduced inside the quote")
14+
case _ => Expr("not matched")

0 commit comments

Comments
 (0)