Skip to content

Commit 41ea7f6

Browse files
committed
Refine error messages
1 parent 35a00cd commit 41ea7f6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

compiler/src/dotty/tools/dotc/transform/init/Errors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ object Errors:
8282

8383
case class AccessCold(field: Symbol, trace: Seq[Tree]) extends Error:
8484
def show(using Context): String =
85-
"Access field on a value with an unknown initialization status." + stacktrace()
85+
"Access field " + field.show + " on a value with a cold object." + stacktrace()
8686

8787
case class CallCold(meth: Symbol, trace: Seq[Tree]) extends Error:
8888
def show(using Context): String =
89-
"Call method on a value with an unknown initialization." + stacktrace()
89+
"Call method " + meth.show + " on a value with an cold object." + stacktrace()
9090

9191
case class CallUnknown(meth: Symbol, trace: Seq[Tree]) extends Error:
9292
def show(using Context): String =

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ object Semantic:
5656
case ThisRef(klass) =>
5757
"ThisRef[" + klass.show + "]"
5858
case Warm(klass, outer, ctor, args) =>
59-
"Warm[" + klass.show + "] { outer = " + outer.show + ", args = " + args.map(_.show).mkString("(", ", ", ")") + " }"
59+
val argsText = if args.nonEmpty then ", args = " + args.map(_.show).mkString("(", ", ", ")") else ""
60+
"Warm[" + klass.show + "] { outer = " + outer.show + argsText + " }"
6061
case Fun(expr, thisV, klass) =>
6162
"Fun { this = " + thisV.show + ", owner = " + klass.show + " }"
6263
case RefSet(values) =>
@@ -1080,7 +1081,7 @@ object Semantic:
10801081
eval(body, thisV, klass)
10811082
}
10821083
given Trace = Trace.empty.add(body)
1083-
res.promote("The function return value is not fully initialized.")
1084+
res.promote("The function return value is not fully initialized. Found = " + res.show + ". ")
10841085
}
10851086
if errors.nonEmpty then
10861087
reporter.report(UnsafePromotion(msg, trace.toVector, errors.head))
@@ -1124,12 +1125,12 @@ object Semantic:
11241125
withTrace(Trace.empty) {
11251126
val args = member.info.paramInfoss.flatten.map(_ => ArgInfo(Hot, Trace.empty))
11261127
val res = warm.call(member, args, receiver = NoType, superType = NoType)
1127-
res.promote("Cannot prove that the return value of " + member + " is fully initialized.")
1128+
res.promote("Cannot prove that the return value of " + member.show + " is fully initialized. Found = " + res.show + ". ")
11281129
}
11291130
else
11301131
withTrace(Trace.empty) {
11311132
val res = warm.select(member)
1132-
res.promote("Cannot prove that the field " + member + " is fully initialized.")
1133+
res.promote("Cannot prove that the field " + member.show + " is fully initialized. Found = " + res.show + ". ")
11331134
}
11341135
end for
11351136
end for
@@ -1230,7 +1231,7 @@ object Semantic:
12301231
/** Utility definition used for better error-reporting of argument errors */
12311232
case class ArgInfo(value: Value, trace: Trace):
12321233
def promote: Contextual[Unit] = withTrace(trace) {
1233-
value.promote("Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak.")
1234+
value.promote("Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak. \nFound = " + value.show + ". ")
12341235
}
12351236

12361237
/** Evaluate an expression with the given value for `this` in a given class `klass`
@@ -1395,14 +1396,14 @@ object Semantic:
13951396
case Match(selector, cases) =>
13961397
val res = eval(selector, thisV, klass)
13971398
extendTrace(selector) {
1398-
res.ensureHot("The value to be matched needs to be fully initialized.")
1399+
res.ensureHot("The value to be matched needs to be fully initialized. Found = " + res.show + ". ")
13991400
}
14001401
eval(cases.map(_.body), thisV, klass).join
14011402

14021403
case Return(expr, from) =>
14031404
val res = eval(expr, thisV, klass)
14041405
extendTrace(expr) {
1405-
res.ensureHot("return expression must be fully initialized.")
1406+
res.ensureHot("return expression must be fully initialized. Found = " + res.show + ". ")
14061407
}
14071408

14081409
case WhileDo(cond, body) =>

0 commit comments

Comments
 (0)