Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8adc284

Browse files
committed
Prevent crash in SAM conversion with mismatched arity
rename test file fix fix test address reviews
1 parent e449935 commit 8adc284

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,11 +1687,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16871687
val restpe = mt.resultType match
16881688
case mt: MethodType => mt.toFunctionType(isJava = samParent.classSymbol.is(JavaDefined))
16891689
case tp => tp
1690-
(formals,
1691-
if (mt.isResultDependent)
1692-
untpd.InLambdaTypeTree(isResult = true, (_, syms) => restpe.substParams(mt, syms.map(_.termRef)))
1693-
else
1694-
typeTree(restpe))
1690+
val tree =
1691+
if (mt.isResultDependent) {
1692+
if (formals.length != defaultArity)
1693+
typeTree(WildcardType)
1694+
else
1695+
untpd.InLambdaTypeTree(isResult = true, (_, syms) => restpe.substParams(mt, syms.map(_.termRef)))
1696+
} else
1697+
typeTree(restpe)
1698+
(formals, tree)
16951699
case _ =>
16961700
(List.tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree())
16971701
}

‎tests/neg/i123577.check‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i123577.scala:11:4 ------------------------------------------------------------
2+
11 | (msg: String) => ??? // error
3+
| ^^^^^^^^^^^^^^^^^^^^
4+
| Found: String => Nothing
5+
| Required: MillRpcChannel
6+
|
7+
| longer explanation available when compiling with `-explain`

‎tests/neg/i123577.scala‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait MillRpcMessage {
2+
type Response
3+
}
4+
5+
trait MillRpcChannel {
6+
def apply(requestId: Long, input: MillRpcMessage): input.Response
7+
}
8+
9+
object MillRpcChannel {
10+
def createChannel: MillRpcChannel = {
11+
(msg: String) => ??? // error
12+
}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /