Skip to content

Commit 745236a

Browse files
committed
Refine condition when to check and improve error message
1 parent c5eb52e commit 745236a

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
345345
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
346346
for arg <- args do
347347
checkInferredWellFormed(arg)
348-
if !arg.span.isSynthetic then
348+
val isInferred = arg.isInstanceOf[InferredTypeTree] || arg.span.isSynthetic
349+
if !isInferred then
349350
// only check explicit type arguments. We rely on inferred type arguments
350351
// to either have good bounds (if they come from a constraint), or be derived
351352
// from values that recursively need to have good bounds.

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ object Checking {
8686
def checkBounds(args: List[tpd.Tree], tl: TypeLambda)(using Context): Unit =
8787
checkBounds(args, tl.paramInfos, _.substParams(tl, _))
8888

89-
def checkGoodBounds(tpe: Type, pos: SrcPos)(using Context): Boolean = tpe.dealias match
90-
case tpe: TypeRef =>
91-
checkGoodBounds(tpe.info, pos)
92-
case TypeBounds(lo, hi) if !(lo <:< hi) =>
93-
report.error(i"type argument has unrealizable bounds $tpe", pos)
94-
false
95-
case _ =>
96-
true
89+
def checkGoodBounds(tpe: Type, pos: SrcPos)(using Context): Boolean =
90+
def recur(tp: Type) = tp.dealias match
91+
case tp: TypeRef =>
92+
checkGoodBounds(tp.info, pos)
93+
case TypeBounds(lo, hi) if !(lo <:< hi) =>
94+
val argStr = if tp eq tpe then "" else i" $tpe"
95+
report.error(i"type argument$argStr has potentially unrealizable bounds $tp", pos)
96+
false
97+
case _ =>
98+
true
99+
recur(tpe)
97100

98101
/** Check applied type trees for well-formedness. This means
99102
* - all arguments are within their corresponding bounds

tests/neg/i15568.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-- Error: tests/neg/i15568.scala:3:15 ----------------------------------------------------------------------------------
22
3 |type Bar = Foo[? >: Int <: String] // error
33
| ^
4-
| type argument has unrealizable bounds >: Int <: String
4+
| type argument has potentially unrealizable bounds >: Int <: String

tests/neg/tate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
def coerce[T, U](t: T): U = {
77
lazy val bound: Bound[U, _ >: T] = ??? // error: >: T does not conform to upper bound
88
def bind = new Bind[U] {}
9-
bind.bad(bound, t) // error: type argument has unrealizable bounds
9+
bind.bad(bound, t)
1010
}
1111
}

0 commit comments

Comments
 (0)