Skip to content

Commit 2df386b

Browse files
authored
Merge pull request #6217 from dotty-staging/fix/i6188
Fix #6188
2 parents 54fb992 + 414d7b7 commit 2df386b

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,10 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
961961
}
962962

963963
def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context): Tree = track("typedTypeApply") {
964+
if (ctx.mode.is(Mode.Pattern)) {
965+
return errorTree(tree, "invalid pattern")
966+
}
967+
964968
val isNamed = hasNamedArg(tree.args)
965969
val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
966970
record("typedTypeApply")

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ class ReTyper extends Typer with ReChecking {
7575
}
7676

7777
override def typedUnApply(tree: untpd.UnApply, selType: Type)(implicit ctx: Context): UnApply = {
78-
val fun1 = typedUnadapted(tree.fun, AnyFunctionProto)
78+
val fun1 = {
79+
// retract PatternOrTypeBits like in typedExpr
80+
val ctx1 = ctx.retractMode(Mode.PatternOrTypeBits)
81+
typedUnadapted(tree.fun, AnyFunctionProto)(ctx1)
82+
}
7983
val implicits1 = tree.implicits.map(typedExpr(_))
8084
val patterns1 = tree.patterns.mapconserve(pat => typed(pat, pat.tpe))
8185
untpd.cpy.UnApply(tree)(fun1, implicits1, patterns1).withType(tree.tpe)

tests/neg/i6188.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Foo {
2+
def foo[T]: Int = 9
3+
4+
def bar =
5+
Option(9) match {
6+
case Some(foo[Int]) => // error
7+
}
8+
}

tests/neg/parser-stability-15.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ class x0 {
33
def x1 =
44
x2 match // error
55
] // error
6-
case x3[] => x0 // error // error // error
6+
case x3[] => x0 // error // error
77
// error

0 commit comments

Comments
 (0)