From 7a9fa8aab76474024ea5f47b730b93b054b22aa8 Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Wed, 12 Jun 2024 10:20:00 -0400 Subject: [PATCH] : fix test and remove condition-to-string method * Remove `condition-to-string()` because `condition-to-string()` already does the same job. * Add `make-condition()` 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. --- .../common-dylan/common-extensions.rst | 14 ++++++++++---- sources/common-dylan/format.dylan | 7 ------- .../tests/condition-test-utilities.dylan | 6 ++++++ sources/dylan/condition-extras.dylan | 10 +++++++--- sources/dylan/tests/specification.dylan | 8 +++++++- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/documentation/source/library-reference/common-dylan/common-extensions.rst b/documentation/source/library-reference/common-dylan/common-extensions.rst index 7bb3fffe67..e5d853c3da 100644 --- a/documentation/source/library-reference/common-dylan/common-extensions.rst +++ b/documentation/source/library-reference/common-dylan/common-extensions.rst @@ -132,7 +132,7 @@ The extensions are: .. generic-function:: condition-to-string :open: - Returns a string representation of a condition object. + Returns a :drm:`` representation of a condition object. :signature: condition-to-string *condition* => *string* @@ -142,9 +142,15 @@ The extensions are: :description: Returns a string representation of a general instance of - :drm:``. There is a method on - :class:`` and method on - :drm:``. + :drm:``. + + 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:``, usually via one of its + subclasses, :drm:``, :drm:``, or + :drm:``. 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: diff --git a/sources/common-dylan/format.dylan b/sources/common-dylan/format.dylan index 6860ddcfac..cdf63103f8 100644 --- a/sources/common-dylan/format.dylan +++ b/sources/common-dylan/format.dylan @@ -588,13 +588,6 @@ define method condition-to-string condition-format-arguments(condition)) end method condition-to-string; -define method condition-to-string - (error :: ) => (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 :: , condition :: ) => () diff --git a/sources/common-dylan/tests/condition-test-utilities.dylan b/sources/common-dylan/tests/condition-test-utilities.dylan index d9ca4d8ec2..c47811638e 100644 --- a/sources/common-dylan/tests/condition-test-utilities.dylan +++ b/sources/common-dylan/tests/condition-test-utilities.dylan @@ -66,6 +66,12 @@ define method test-condition (condition :: ) => () )) end method test-condition; +define method make-condition (class == ) => (c :: ) + make(, + value: #"type-error-value", + type: ) +end method; + define method test-condition (condition :: ) => () next-method(); do(method (function) function(condition) end, diff --git a/sources/dylan/condition-extras.dylan b/sources/dylan/condition-extras.dylan index 5d9e09fb86..be53f97fff 100644 --- a/sources/dylan/condition-extras.dylan +++ b/sources/dylan/condition-extras.dylan @@ -89,9 +89,13 @@ end method abort; /// TYPE-ERRORS -define open class (, ) // Should be sealed? - constant slot type-error-value, init-keyword: value:; - constant slot type-error-expected-type :: , init-keyword: type:; +// Note that the DRM only mentions as a superclass. Speculation: we +// additionally subclass because there is special support +// for its condition-format-string and condition-format-arguments in the +// debugger manager. +define sealed class (, ) + constant slot type-error-value, required-init-keyword: value:; + constant slot type-error-expected-type :: , required-init-keyword: type:; end class ; define method make diff --git a/sources/dylan/tests/specification.dylan b/sources/dylan/tests/specification.dylan index 81daafbb38..46c50f63da 100644 --- a/sources/dylan/tests/specification.dylan +++ b/sources/dylan/tests/specification.dylan @@ -238,7 +238,7 @@ define interface-specification-suite dylan-conditions-specification-suite () open abstract class (); sealed instantiable class (); sealed instantiable class (); - sealed instantiable class (); + sealed instantiable class (); // make-test-instance method below. open abstract class (); /// Restarts @@ -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 == ) => (err :: ) + make(, + value: #"type-error-value", + type: ) +end method; + //--- Bindings not defined by the DRM //---*** Are there any others?