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

<type-error>: fix test and remove condition-to-string method #1614

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ The extensions are:
.. generic-function:: condition-to-string
:open:

Returns a string representation of a condition object.
Returns a :drm:`<string>` representation of a condition object.

:signature: condition-to-string *condition* => *string*

Expand All @@ -142,9 +142,15 @@ The extensions are:
:description:

Returns a string representation of a general instance of
:drm:`<condition>`. There is a method on
:class:`<format-string-condition>` and method on
:drm:`<type-error>`.
:drm:`<condition>`.

Note that it is often not necessary to write a method on this generic
function for your condition classes because you can use the method
provided by :class:`<simple-condition>`, usually via one of its
subclasses, :drm:`<simple-error>`, :drm:`<simple-warning>`, or
:drm:`<simple-restart>`. Simply make your condition a subclass of one of
these classes and provide the ``format-string:`` and ``format-arguments:``
init keywords.

.. macro:: debug-assert
:statement:
Expand Down
7 changes: 0 additions & 7 deletions sources/common-dylan/format.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,6 @@ define method condition-to-string
condition-format-arguments(condition))
end method condition-to-string;

define method condition-to-string
(error :: <type-error>) => (string :: <string>)
format-to-string("%= is not of type %=",
type-error-value(error),
type-error-expected-type(error))
end method condition-to-string;

define method print-pretty-name
(buffer :: <string-buffer>, condition :: <condition>)
=> ()
Expand Down
6 changes: 6 additions & 0 deletions sources/common-dylan/tests/condition-test-utilities.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ define method test-condition (condition :: <type-error>) => ()
))
end method test-condition;

define method make-condition (class == <type-error>) => (c :: <type-error>)
make(<type-error>,
value: #"type-error-value",
type: <string>)
end method;

define method test-condition (condition :: <simple-warning>) => ()
next-method();
do(method (function) function(condition) end,
Expand Down
10 changes: 7 additions & 3 deletions sources/dylan/condition-extras.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ end method abort;

/// TYPE-ERRORS

define open class <type-error> (<error>, <format-string-condition>) // Should be sealed?
constant slot type-error-value, init-keyword: value:;
constant slot type-error-expected-type :: <type>, init-keyword: type:;
// Note that the DRM only mentions <error> as a superclass. Speculation: we
// additionally subclass <simple-condition> because there is special support
// for its condition-format-string and condition-format-arguments in the
// debugger manager.
define sealed class <type-error> (<error>, <simple-condition>)
constant slot type-error-value, required-init-keyword: value:;
constant slot type-error-expected-type :: <type>, required-init-keyword: type:;
end class <type-error>;

define method make
Expand Down
8 changes: 7 additions & 1 deletion sources/dylan/tests/specification.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ define interface-specification-suite dylan-conditions-specification-suite ()
open abstract class <serious-condition> (<condition>);
sealed instantiable class <simple-error> (<error>);
sealed instantiable class <simple-warning> (<warning>);
sealed instantiable class <type-error> (<error>);
sealed instantiable class <type-error> (<error>); // make-test-instance method below.
open abstract class <warning> (<condition>);

/// Restarts
Expand Down Expand Up @@ -286,6 +286,12 @@ define interface-specification-suite dylan-conditions-specification-suite ()
expected-to-fail-reason: "https://github.com/dylan-lang/opendylan/issues/1295";
end dylan-conditions-specification-suite;

define sideways method make-test-instance (class == <type-error>) => (err :: <type-error>)
make(<type-error>,
value: #"type-error-value",
type: <string>)
end method;

//--- Bindings not defined by the DRM
//---*** Are there any others?

Expand Down
Loading