Skip to content

Commit

Permalink
<type-error>: fix test and remove condition-to-string method
Browse files Browse the repository at this point in the history
* Remove `condition-to-string(<type-error>)` because
  `condition-to-string(<simple-condition>)` already does the same job.

* Add `make-condition(<type-error>)` to supply the required init args for the
  test.

* Make both value: and type: be required init keywords. Potentially
  controversial since they're not specified as required in the DRM, but the
  error is meaningless without these slots set and this would have uncovered the
  test suite bug right away.
  • Loading branch information
cgay committed Jun 12, 2024
1 parent 54f53bb commit 7a9fa8a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
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

0 comments on commit 7a9fa8a

Please sign in to comment.