Possibly a lazyweb question but is it possible to ...
# compiler
z
Possibly a lazyweb question but is it possible to report diagnostics in FIR with a dynamically computed string? For example - a string that contains more specific context/references to the code being reported. All the examples I’ve seen just maintain a static mapping of diagnostics to message strings
d
You can declare your diagnostic as diagnostics with parameters (up to 4) and configure its message with these arguments Take, for example,
TYPEALIAS_EXPANSION_DEPRECATION_ERROR
It's declared as
KtDiagnosticFactory3
with three parameters Its message
"''{0}'' uses ''{1}'', which is an error. {2}."
contains
{0}
,
{1}
and
{2}
as placeholders for actual arguments In each parameter you can use whatever type you want, just provide the proper renderer for them (renderer is a basically
(T) -> String
converter)
z
Ohhhhh I see I see. Thanks!
d
You can even create a diagnostic with a one
String
parameter, declare its message as
"{0}"
and compute the whole message at the reporting side
z
Perfect