Skip to content

Commit 4c122f4

Browse files
committed
Try improving error
1 parent 6126bf4 commit 4c122f4

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,10 +1478,10 @@ object messages {
14781478
val explanation = ""
14791479
}
14801480

1481-
case class DoesNotConformToBound(tpe: Type, which: String, bound: Type)(
1481+
case class DoesNotConformToBound(tpe: Type, which: String, bound: Type, inferred: Boolean)(
14821482
err: typer.ErrorReporting.Errors)(implicit ctx: Context)
14831483
extends Message(DoesNotConformToBoundID) {
1484-
val msg = hl"Type argument ${tpe} does not conform to $which bound $bound ${err.whyNoMatchStr(tpe, bound)}"
1484+
val msg = hl"${if (inferred) "Inferred type" else "Type"} argument $tpe does not conform to $which bound $bound ${err.whyNoMatchStr(tpe, bound)}"
14851485
val kind = "Type Mismatch"
14861486
val explanation = ""
14871487
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ object Checking {
4545
}
4646
}
4747
for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate)) {
48-
if (arg.pos.isZeroExtent)
49-
ctx.error(
50-
DoesNotConformToBound(arg.tpe, which, bound)(err),
51-
arg.pos.focus)
52-
else
53-
ctx.error(hl"inferred type ${arg.tpe} violates $which bound $bound", arg.pos.focus)
48+
println(s"arg.pos ${arg.pos}, ${arg.pos.isSynthetic}")
49+
ctx.error(
50+
DoesNotConformToBound(arg.tpe, which, bound, arg.pos.isZeroExtent)(err),
51+
arg.pos.focus)
5452
}
5553
}
5654

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,11 @@ class ErrorMessagesTests extends ErrorMessagesTest {
614614
.expect { (ictx, messages) =>
615615
implicit val ctx: Context = ictx
616616
assertMessageCount(1, messages)
617-
val DoesNotConformToBound(tpe, which, bound) :: Nil = messages
617+
val DoesNotConformToBound(tpe, which, bound, inferred) :: Nil = messages
618618
assertEquals("Int", tpe.show)
619619
assertEquals("upper", which)
620620
assertEquals("List[Int]", bound.show)
621+
assertEquals(true, inferred)
621622
}
622623

623624
@Test def doesNotConformToSelfType =

0 commit comments

Comments
 (0)