(setf fdefinition) and (setf symbol-function) are type-unsafe

Bug #659173 reported by Nikodemus Siivola
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Triaged
Medium
Unassigned

Bug Description

CL-USER> (declaim (ftype (function (t) (values string)) quux))
; No value
CL-USER> (setf (symbol-function 'quux) (lambda (x) (list x)))
#<FUNCTION (LAMBDA (X)) {1002D1F2F9}>
CL-USER> (defun foo () (length (quux 128)))
FOO
CL-USER> (foo)
128

Tags: types
Changed in sbcl:
status: In Progress → Triaged
Revision history for this message
Alastair Bridgewater (alastair-bridgewater) wrote :

CLHS for System Class FUNCTION says "Thus, an ftype declaration for a function describes calls to the function, not the actual definition of the function."

Earlier in the same page, it says "The list form of the function type-specifier can be used only for declaration and not for discrimination."

On the whole, the MOST that I would expect here is an error that (128) is not of type STRING, signaled from FOO, and that's more a matter of not intrinsically believing FTYPE declarations than (SETF FDEFINITION) or (SETF SYMBOL-FUNCTION) not being typesafe.

Revision history for this message
Alastair Bridgewater (alastair-bridgewater) wrote :

Actually, let's go a step further here: (lambda (x) (if (integerp x) (logand x 31) (car x))) has type (function ((or integer list)) (values t)). It may be used when a (function (integer) (values (mod 32))) is expected with no problem. But (lambda (x) (if (integerp x) (code-char x) (car x))) also has type (function ((or integer list)) (values t)), and clearly may NOT be used in such a situation. This is not the line of argument from CLHS, but does demonstrate the utter futility of expecting any serious level of "type safety" from (setf fdefinition) or (setf symbol-function) beyond simply ensuring that the value is a subtype of FUNCTION.

Can we redefine this in terms of the default policy and trust in FTYPE declarations at the call site, rather than in terms of the FDEFINITION and SYMBOL-FUNCTION accessors, or simply declare the bug to be invalid?

Revision history for this message
Douglas Katzman (dougk) wrote :

highly important but open for 9 years? Not really. Decreasing to "medium" importance.

Changed in sbcl:
importance: High → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.