Repository navigation
Error has JavaScript's name and toString() - #131
Merged
Merged
Conversation
- `name` ("Error", and each subclass its own: RangeError, TypeError, SyntaxError, ReferenceError,
SuppressedError) is a field a subclass may set (`this.name = "ValidationError"`)
- `toString()` is "Name: message", or the name alone without a message
- so an Error prints, and is made a string, as in JavaScript (`${e}`, `"" + e`, print(e), console.log(e)); it
was refused (no toString), and a caught one held in `any` printed "[object Object]"
- `message` stays the first field after the vtable, where the report of an uncaught exception reads it; `name`
is declared after the constructor's fields
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h takes as a failure Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Errorand its subclasses get JavaScript'snameandtoString().nameis"Error", and each subclass sets its own:RangeError,TypeError,SyntaxError,ReferenceError,SuppressedError. It is a plain field, so a program's subclass may set it (this.name = "ValidationError").toString()gives"Name: message", or the name alone when there is no message.Errorprints and turns into a string as in JavaScript (${e},"" + e,print(e),console.log(e)). Before, this was refused because there was notoString, and a caught error held inanyprinted[object Object].Layout
messagestays the first field after the vtable, because the compiler's uncaught-exception report reads it there (UncaughtException.h).nameis declared after the constructor's fields. Checked:throw new RangeError("boom")still reportsuncaught exception: RangeError: boom, both under the JIT and from an exe.Testing
tests/error_name_tostring.ts: passes under gc, rc, none and own with the compiler of Node's two string forms; -mm=own inference crash (module walk from threaded pass) TypeScriptCompiler#1080, and with the released compiler this repository's CI uses.any:console.log("E", e)printsE Error: ERRwith the compiler of #1080.🤖 Generated with Claude Code