Skip to content

Commit 5290153

Browse files
committed
Don't synthesize context functions with embedded wildcards
Don't synthesize context functions with embedded wildcards in their parameter types. This leads to a crash later when we typecheck the closure.
1 parent 8324940 commit 5290153

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ class Typer extends Namer
12031203
* @post: If result exists, `paramIndex` is defined for the name of
12041204
* every parameter in `params`.
12051205
*/
1206-
lazy val calleeType: Type = untpd.stripAnnotated(fnBody) match {
1206+
lazy val calleeType: Type = untpd.stripAnnotated(untpd.unsplice(fnBody)) match {
12071207
case ident: untpd.Ident if isContextual =>
12081208
val ident1 = typedIdent(ident, WildcardType)
12091209
val tp = ident1.tpe.widen
@@ -2700,7 +2700,7 @@ class Typer extends Namer
27002700
// see tests/pos/i7778b.scala
27012701

27022702
val paramTypes = {
2703-
val hasWildcard = formals.exists(_.isInstanceOf[WildcardType])
2703+
val hasWildcard = formals.exists(_.existsPart(_.isInstanceOf[WildcardType], stopAtStatic = true))
27042704
if hasWildcard then formals.map(_ => untpd.TypeTree())
27052705
else formals.map(untpd.TypeTree)
27062706
}

tests/pos/i11350.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
case class A[T](action: A[T] ?=> String) // error
2+
3+
class A1[T](action: A1[T] ?=> String = (_: A1[T]) ?=> "") // works
4+
case class A2[T](action: A2[?] ?=> String) // works
5+
case class A3[T](action: A3[T] => String) // works as well
6+
7+
class A4[T](action: A1[T] ?=> String = "") // error

0 commit comments

Comments
 (0)