Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fraya opened this issue Apr 2, 2022 · 3 comments
Open

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

fraya opened this issue Apr 2, 2022 · 3 comments

Comments

@fraya
Copy link
Member

fraya commented Apr 2, 2022

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.

@cgay
Copy link
Member

cgay commented Apr 2, 2022

define /* sealed */ method print-message (object :: <condition>, stream :: <stream>)
=> ();
//---*** This method is broken right now. It should just call report-condition.
//---*** If this interim bit of code is not good enough, then we'll have to do
//---*** something better (assuming we can't just fix report-condition).
//---*** report-condition(object, stream);
dynamic-bind (*print-escape?* = #f) // print as a string
print-object(object, stream)
end
end method;

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

@cgay
Copy link
Member

cgay commented Jun 9, 2024

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
Copy link
Member

cgay commented Jun 9, 2024

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>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants