Opened 12 years ago

Closed 9 years ago

#221 closed enhancement (fixed)

defstruct accessors don't check argument type

Reported by: rongarret Owned by: gb
Priority: major Milestone:
Component: ANSI CL Compliance Version:
Keywords: defstruct Cc:

Description

? (defstruct foo x) FOO ? (defstruct baz y) BAZ ? (foo-x (make-baz)) NIL

Should be an error.

Change History (4)

comment:1 Changed 12 years ago by gb

  • Status changed from new to assigned
  • Type changed from defect to enhancement

Could be an error; all that the spec says (in the dictionary entry for DEFSTRUCT) is that an implementation might check for incorrect use of reader functions.

There are both advantages and costs to doing so, and it might be good to be able to specify (via OPTIMIZE declarations) whether one preferred the speed of not checking vs the safety of checking the structure type. The way that DEFSTRUCT was actually implemented (way back when), it was assumed that SPACE was a prevailing concern, and one consequence of that assumption is that

? (eq #'foo-x #'baz-y)

is true in your example.

There are different concerns 20 years later, and I'd agree that being able to get more type-safety when you want it would be a good thing.

In practice, calls to DEFSTRUCT reader and writer functions are usually inlined, so one approach to achieving more type-safety would be to make the actual (out-of-line) functions be unique and have them do structure-type checks, to not do those checks when the call is inlined, and to (maybe) be a little less willing to inline calls to DEFSTRUCT accessors.

The current behavior (where there's no check for incorrect use of accessors) is certainly in line with what ANSI CL says about this (which is basically that it's up to the implementation.)

comment:2 Changed 11 years ago by jch

Note that fixing this naively might break the case described in #390.

comment:3 Changed 11 years ago by rme

  • Keywords defstruct added

comment:4 Changed 9 years ago by rme

  • Resolution set to fixed
  • Status changed from assigned to closed

This is fixed now.

See r14258 and follow-on fixes.

Hey, it only took three years!

Note: See TracTickets for help on using tickets.