Skip to content

Commit 7a9fa8a

Browse files
committed
<type-error>: fix test and remove condition-to-string method
* 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.
1 parent 54f53bb commit 7a9fa8a

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

documentation/source/library-reference/common-dylan/common-extensions.rst

+10-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ The extensions are:
132132
.. generic-function:: condition-to-string
133133
:open:
134134

135-
Returns a string representation of a condition object.
135+
Returns a :drm:`<string>` representation of a condition object.
136136

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

@@ -142,9 +142,15 @@ The extensions are:
142142
:description:
143143

144144
Returns a string representation of a general instance of
145-
:drm:`<condition>`. There is a method on
146-
:class:`<format-string-condition>` and method on
147-
:drm:`<type-error>`.
145+
:drm:`<condition>`.
146+
147+
Note that it is often not necessary to write a method on this generic
148+
function for your condition classes because you can use the method
149+
provided by :class:`<simple-condition>`, usually via one of its
150+
subclasses, :drm:`<simple-error>`, :drm:`<simple-warning>`, or
151+
:drm:`<simple-restart>`. Simply make your condition a subclass of one of
152+
these classes and provide the ``format-string:`` and ``format-arguments:``
153+
init keywords.
148154

149155
.. macro:: debug-assert
150156
:statement:

sources/common-dylan/format.dylan

-7
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,6 @@ define method condition-to-string
588588
condition-format-arguments(condition))
589589
end method condition-to-string;
590590

591-
define method condition-to-string
592-
(error :: <type-error>) => (string :: <string>)
593-
format-to-string("%= is not of type %=",
594-
type-error-value(error),
595-
type-error-expected-type(error))
596-
end method condition-to-string;
597-
598591
define method print-pretty-name
599592
(buffer :: <string-buffer>, condition :: <condition>)
600593
=> ()

sources/common-dylan/tests/condition-test-utilities.dylan

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ define method test-condition (condition :: <type-error>) => ()
6666
))
6767
end method test-condition;
6868

69+
define method make-condition (class == <type-error>) => (c :: <type-error>)
70+
make(<type-error>,
71+
value: #"type-error-value",
72+
type: <string>)
73+
end method;
74+
6975
define method test-condition (condition :: <simple-warning>) => ()
7076
next-method();
7177
do(method (function) function(condition) end,

sources/dylan/condition-extras.dylan

+7-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,13 @@ end method abort;
8989

9090
/// TYPE-ERRORS
9191

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

97101
define method make

sources/dylan/tests/specification.dylan

+7-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ define interface-specification-suite dylan-conditions-specification-suite ()
238238
open abstract class <serious-condition> (<condition>);
239239
sealed instantiable class <simple-error> (<error>);
240240
sealed instantiable class <simple-warning> (<warning>);
241-
sealed instantiable class <type-error> (<error>);
241+
sealed instantiable class <type-error> (<error>); // make-test-instance method below.
242242
open abstract class <warning> (<condition>);
243243

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

289+
define sideways method make-test-instance (class == <type-error>) => (err :: <type-error>)
290+
make(<type-error>,
291+
value: #"type-error-value",
292+
type: <string>)
293+
end method;
294+
289295
//--- Bindings not defined by the DRM
290296
//---*** Are there any others?
291297

0 commit comments

Comments
 (0)