Skip to content

Commit a2b90ac

Browse files
authored
Merge pull request #10100 from dotty-staging/fix-10082
Fix #10082: show friendly error message related to type inference
2 parents 4cf3bf0 + 82dbdf6 commit a2b90ac

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ trait Inferencing { this: Typer =>
508508
// found : Int(1)
509509
// required: String
510510
// val y: List[List[String]] = List(List(1))
511-
val hasUnreportedErrors = state.reporter.hasUnreportedErrors
511+
if state.reporter.hasUnreportedErrors then return tree
512+
512513
def constraint = state.constraint
513514
type InstantiateQueue = mutable.ListBuffer[(TypeVar, Boolean)]
514515
val toInstantiate = new InstantiateQueue
@@ -521,7 +522,7 @@ trait Inferencing { this: Typer =>
521522
typr.println(i"interpolate non-occurring $tvar in $state in $tree: $tp, fromBelow = ${tvar.hasLowerBound}, $constraint")
522523
toInstantiate += ((tvar, tvar.hasLowerBound))
523524
}
524-
else if (!hasUnreportedErrors)
525+
else
525526
if (v.intValue != 0) {
526527
typr.println(i"interpolate $tvar in $state in $tree: $tp, fromBelow = ${v.intValue == 1}, $constraint")
527528
toInstantiate += ((tvar, v.intValue == 1))

tests/neg/i10082.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Kotlin:
2+
def it[T](using t: T) = t
3+
def fun[T, U](fn: T ?=> U)(x: T): U = fn(using x)
4+
5+
import Kotlin.{fun, it}
6+
7+
def Test = List(1).map(fun(it + 1)) // error

tests/neg/i9568.check

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-- Error: tests/neg/i9568.scala:13:10 ----------------------------------------------------------------------------------
22
13 | blaMonad.foo(bla) // error: diverges
33
| ^
4-
|no implicit argument of type => Monad[([_$3] =>> Any)] was found for parameter ev of method blaMonad in object Test.
5-
|I found:
4+
| no implicit argument of type => Monad[F] was found for parameter ev of method blaMonad in object Test.
5+
| I found:
66
|
7-
| Test.blaMonad[Nothing, S](Test.blaMonad[F, S])
7+
| Test.blaMonad[Nothing, S](Test.blaMonad[F, S])
88
|
9-
|But method blaMonad in object Test does not match type => Monad[Nothing].
9+
| But method blaMonad in object Test does not match type => Monad[Nothing].

0 commit comments

Comments
 (0)