Skip to content

Commit 6285661

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 6285661

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-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/neg/i11350.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E081] Type Error: tests/neg/i11350.scala:1:39 ----------------------------------------------------------------------
2+
1 |class A1[T](action: A1[T] ?=> String = "") // error
3+
| ^
4+
| Missing parameter type
5+
|
6+
| I could not infer the type of the parameter evidence$1.
7+
| What I could infer was: A1[<?>]
8+
-- [E081] Type Error: tests/neg/i11350.scala:2:39 ----------------------------------------------------------------------
9+
2 |class A2[T](action: A1[T] ?=> String = summon[A1[T]]) // error
10+
| ^
11+
| Missing parameter type
12+
|
13+
| I could not infer the type of the parameter evidence$2.
14+
| What I could infer was: A1[<?>]

tests/neg/i11350.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class A1[T](action: A1[T] ?=> String = "") // error
2+
class A2[T](action: A1[T] ?=> String = summon[A1[T]]) // error

tests/pos/i11350.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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

0 commit comments

Comments
 (0)