Skip to content

Commit 52fdea0

Browse files
committed
Fix #10082: show friendly error message related to type inference
The type `site` in class `NotAMember` might be an uninitialized type variable, but is initialized when we display the error message. It results in confusing error message as in #10082. We avoid instantiating the type variable when there is a unreported error in current typerstate.
1 parent a5f8e2b commit 52fdea0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ trait Inferencing { this: Typer =>
509509
// required: String
510510
// val y: List[List[String]] = List(List(1))
511511
val hasUnreportedErrors = state.reporter.hasUnreportedErrors
512+
if hasUnreportedErrors then return tree
513+
512514
def constraint = state.constraint
513515
type InstantiateQueue = mutable.ListBuffer[(TypeVar, Boolean)]
514516
val toInstantiate = new InstantiateQueue
@@ -521,7 +523,7 @@ trait Inferencing { this: Typer =>
521523
typr.println(i"interpolate non-occurring $tvar in $state in $tree: $tp, fromBelow = ${tvar.hasLowerBound}, $constraint")
522524
toInstantiate += ((tvar, tvar.hasLowerBound))
523525
}
524-
else if (!hasUnreportedErrors)
526+
else
525527
if (v.intValue != 0) {
526528
typr.println(i"interpolate $tvar in $state in $tree: $tp, fromBelow = ${v.intValue == 1}, $constraint")
527529
toInstantiate += ((tvar, v.intValue == 1))

tests/neg/i10082.scala

Lines changed: 7 additions & 0 deletions
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

0 commit comments

Comments
 (0)