-
Notifications
You must be signed in to change notification settings - Fork 1
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
TRY/except ignores the typespec of its function argument #1514
Comments
Submitted by: abolka In the core-tests suite. |
Submitted by: szeng "despite the fact that normally arguments without typespecs don't accept error! values" This doesn't seem to be true (any more) >> a: make error! [type: 'user id: 'message arg1: "hello"]
** user error: "hello" >> ?? a
a: make error! [
code: 800
type: 'user
id: 'message
arg1: "hello"
arg2: none
arg3: none
near: none
where: none
]
** user error: "hello"
>> c: func [a][if error? a [print "a:" a]]
>> c a
a:
** user error: "hello" |
Submitted by: szeng I think we should check the type of the argument as we do for other functions. |
Submitted by: abolka > I think we should check the type of the argument as we do for other functions. Agreed. I have a fix for that implemented which I'll push in a minute. |
Submitted by: abolka Pull request submitted: https://github.com/rebol/rebol/pull/227 |
Submitted by: szeng I was working on a similar fix. But yours is back compatiable, mine was more strictive on the number of arguments. https://gist.github.com/zsx/9c8628db9bcded698b5a |
TRY/except now checks that the typespec of a handler function actually allows calls with the error value, before calling the handler function. This fixes CureCode issue #1514. metaeducation/rebol-issues#1514
Ren-C does not allow calling functions without spec checking (there are no shortcuts). This part of the design is pervasive. |
Submitted by: BrianH
When you pass a function as the exception handler of TRY/except, that function should have one regular argument, which will be the error that is being handled. However, you don't have to specify a typespec for that argument despite the fact that normally arguments without typespecs don't accept error! values. This is because TRY/except doesn't do the type testing that a normal function call does - it passes in the error! argument anyways.
For that matter, the function doesn't need to take an argument at all, or can take multiple arguments: APPLY/only semantics are used for the function arguments, so none is passed to any additional arguments. This wouldn't necessarily be a problem, but when combined with the lack of type checking it gives us an easy way to crash R3.
The advantage to the lack of type checking is that we don't need to write a verbose type spec in our handlers. The disadvantage is that you can easily crash R3 if you pass the wrong native function as a handler.
It would be a good idea to at least do the type checking when calling native functions, including natives, actions, ops and commands. You can't crash R3 with a regular function or closure in this case, so the type checking isn't as necessary. It might not be a good idea to disallow native functions altogether, but that could be an acceptable alternative to selective type checking if necessary.
CC - Data [ Version: alpha 97 Type: Bug Platform: All Category: Native Reproduce: Always Fixed-in:none ]
The text was updated successfully, but these errors were encountered: