Skip to content

Commit 6a0dbb7

Browse files
oderskyliufengyun
authored andcommitted
Fix crash reported by reviewer
1 parent 2acee5b commit 6a0dbb7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,15 +1549,17 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
15491549
val untpd.PostfixOp(qual, Ident(nme.WILDCARD)) = tree
15501550
val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
15511551
val nestedCtx = ctx.fresh.setNewTyperState()
1552-
var res = typed(qual, pt1)(nestedCtx)
1553-
if (!defn.isFunctionClass(res.tpe.classSymbol)) {
1554-
ctx.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore(res.tpe), tree.pos)
1555-
if (ctx.scala2Mode) {
1556-
// Under -rewrite, patch `x _` to `(() => x)`
1557-
patch(Position(tree.pos.start), "(() => ")
1558-
patch(Position(qual.pos.end, tree.pos.end), ")")
1559-
return typed(untpd.Function(Nil, res))
1560-
}
1552+
val res = typed(qual, pt1)(nestedCtx)
1553+
res match {
1554+
case res @ closure(_, _, _) =>
1555+
case _ =>
1556+
ctx.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore(res.tpe), tree.pos)
1557+
if (ctx.scala2Mode) {
1558+
// Under -rewrite, patch `x _` to `(() => x)`
1559+
patch(Position(tree.pos.start), "(() => ")
1560+
patch(Position(qual.pos.end, tree.pos.end), ")")
1561+
return typed(untpd.Function(Nil, qual), pt)
1562+
}
15611563
}
15621564
nestedCtx.typerState.commit()
15631565
if (ctx.settings.strict.value) {

tests/neg/i3246.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test {
2+
def foo(x: Int) = 1
3+
val bar: () => Int = foo _
4+
}

0 commit comments

Comments
 (0)