opendylan icon indicating copy to clipboard operation
opendylan copied to clipboard

io/format/print-message(<condition>) doesn't work

Open fraya opened this issue 3 years ago • 3 comments

As said in documentation https://opendylan.org/documentation/library-reference/io/format.html#io:format:print-message([condition]) the method print-message(<condition>) doesn't work.

fraya avatar Apr 02 '22 08:04 fraya

https://github.com/dylan-lang/opendylan/blob/89e84131706393e255be12a388853191c12b9d46/sources/io/format.dylan#L74-L83

I wonder what the problem is with report-condition....

cgay avatar Apr 02 '22 21:04 cgay

report-condition(object, stream) is not a thing; it's report-condition(condition) => (). The only way that could be useful is if all errors are reported to *standard-error* or something like that, which is completely inadequate. Which is to say that I'm not sure what the comment above means. Also they don't say how it's broken.

My current problem: I signal a subclass of <format-string-condition> with format-arguments: list(...args...) but when the condition is printed with io/format-err("%s\n", condition) the print-object methods for args aren't called. For example one of the args is a <token> that has a print-object that displays the line number of the token, but it just displays as {<token>}.) Adding this method fixes that:

define method io/print-message (cond :: <lox-error>, stream :: <stream>) => ()
  apply(io/format, stream,
        cond.condition-format-string,
        cond.condition-format-arguments);
  io/force-output(stream);
end method;

This goes directly against what the doc says: "You should not specialize the print-message protocol for subclasses of , but instead extend the print-message protocol to new condition objects by specializing methods on report-condition."

So anyway, maybe we just need a similar method defined on <format-string-condition>, and to delete that comment.

cgay avatar Jun 09 '24 23:06 cgay

The documentation for <format-string-condition> and <simple-condition> is incorrect about one being a superclass of the other. They are the same object. define constant <format-string-condition> = <simple-condition>;

cgay avatar Jun 09 '24 23:06 cgay