Skip to content

Commit d6c5d92

Browse files
committed
addded to type report output of tree, which can't be typed, because in macros pos can point to complete other thing.
1 parent a9a7e70 commit d6c5d92

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ import transform.SymUtils._
242242
}
243243
}
244244

245-
class TypeMismatch(found: Type, expected: Type, addenda: => String*)(using Context)
245+
class TypeMismatch(found: Type, expected: Type, inTree: Option[untpd.Tree], addenda: => String*)(using Context)
246246
extends TypeMismatchMsg(found, expected)(TypeMismatchID):
247247

248248
// replace constrained TypeParamRefs and their typevars by their bounds where possible
@@ -281,7 +281,13 @@ import transform.SymUtils._
281281
val (foundStr, expectedStr) = Formatting.typeDiff(found2, expected2)(using printCtx)
282282
s"""|Found: $foundStr
283283
|Required: $expectedStr""".stripMargin
284-
+ whereSuffix + postScript
284+
+ whereSuffix + postScript
285+
286+
override def explain =
287+
val treeStr = inTree.map(x => s"\nTree: ${x.show}").getOrElse("")
288+
treeStr + "\n" + err.whyNoMatchStr(found, expected)
289+
290+
285291
end TypeMismatch
286292

287293
class NotAMember(site: Type, val name: Name, selected: String, addendum: => String = "")(using Context)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ class TreeChecker extends Phase with SymTransformer {
592592
!isPrimaryConstructorReturn &&
593593
!pt.isInstanceOf[FunOrPolyProto])
594594
assert(tree.tpe <:< pt, {
595-
val mismatch = TypeMismatch(tree.tpe, pt)
595+
val mismatch = TypeMismatch(tree.tpe, pt, Some(tree))
596596
i"""|${mismatch.msg}
597597
|found: ${infoStr(tree.tpe)}
598598
|expected: ${infoStr(pt)}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ trait Applications extends Compatibility {
440440
// it might be healed by an implicit conversion
441441
()
442442
else
443-
fail(TypeMismatch(methType.resultType, resultType))
443+
fail(TypeMismatch(methType.resultType, resultType, None))
444444

445445
// match all arguments with corresponding formal parameters
446446
matchArgs(orderedArgs, methType.paramInfos, 0)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object ErrorReporting {
131131
case If(_, _, elsep @ Literal(Constant(()))) if elsep.span.isSynthetic =>
132132
"\nMaybe you are missing an else part for the conditional?"
133133
case _ => ""
134-
errorTree(tree, TypeMismatch(treeTp, pt, implicitFailure.whyNoConversion, missingElse))
134+
errorTree(tree, TypeMismatch(treeTp, pt, Some(tree), implicitFailure.whyNoConversion, missingElse))
135135
}
136136

137137
/** A subtype log explaining why `found` does not conform to `expected` */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3880,7 +3880,7 @@ class Typer extends Namer
38803880
// - it complicates the protocol
38813881
// - such code patterns usually implies hidden errors in the code
38823882
// - it's safe/sound to reject the code
3883-
report.error(TypeMismatch(tree.tpe, pt, "\npattern type is incompatible with expected type"), tree.srcPos)
3883+
report.error(TypeMismatch(tree.tpe, pt, Some(tree), "\npattern type is incompatible with expected type"), tree.srcPos)
38843884
else
38853885
val cmp =
38863886
untpd.Apply(

0 commit comments

Comments
 (0)