1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

fix scm_setter

* libguile/procs.c (scm_setter): Only get at the setter slot if the pure
  generic actually has a setter.  Needs test.

* test-suite/tests/goops.test ("defining generics"):
  ("defining accessors"): Add `setter' tests.
This commit is contained in:
Andy Wingo 2011-03-08 09:30:33 +01:00
parent 0b0e066a26
commit 534491d0b7
2 changed files with 11 additions and 3 deletions

View file

@ -149,7 +149,8 @@ SCM_PRIMITIVE_GENERIC (scm_setter, "setter", 1, 0, 0,
SCM_GASSERT1 (SCM_STRUCTP (proc), g_scm_setter, proc, SCM_ARG1, FUNC_NAME); SCM_GASSERT1 (SCM_STRUCTP (proc), g_scm_setter, proc, SCM_ARG1, FUNC_NAME);
if (SCM_STRUCT_SETTER_P (proc)) if (SCM_STRUCT_SETTER_P (proc))
return SCM_STRUCT_SETTER (proc); return SCM_STRUCT_SETTER (proc);
if (SCM_PUREGENERICP (proc)) if (SCM_PUREGENERICP (proc)
&& SCM_IS_A_P (proc, scm_class_generic_with_setter))
/* FIXME: might not be an accessor */ /* FIXME: might not be an accessor */
return SCM_GENERIC_SETTER (proc); return SCM_GENERIC_SETTER (proc);
SCM_WTA_DISPATCH_1 (g_scm_setter, proc, SCM_ARG1, FUNC_NAME); SCM_WTA_DISPATCH_1 (g_scm_setter, proc, SCM_ARG1, FUNC_NAME);

View file

@ -1,6 +1,6 @@
;;;; goops.test --- test suite for GOOPS -*- scheme -*- ;;;; goops.test --- test suite for GOOPS -*- scheme -*-
;;;; ;;;;
;;;; Copyright (C) 2001,2003,2004, 2006, 2008, 2009 Free Software Foundation, Inc. ;;;; Copyright (C) 2001,2003,2004, 2006, 2008, 2009, 2011 Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -234,7 +234,11 @@
(eval '(define-generic foo) (current-module)) (eval '(define-generic foo) (current-module))
(eval '(and (is-a? foo <generic>) (eval '(and (is-a? foo <generic>)
(null? (generic-function-methods foo))) (null? (generic-function-methods foo)))
(current-module))))) (current-module)))
(pass-if-exception "getters do not have setters"
exception:wrong-type-arg
(eval '(setter foo) (current-module)))))
(with-test-prefix "defining methods" (with-test-prefix "defining methods"
@ -294,6 +298,9 @@
(null? (generic-function-methods foo-1))) (null? (generic-function-methods foo-1)))
(current-module))) (current-module)))
(pass-if "accessors have setters"
(procedure? (eval '(setter foo-1) (current-module))))
(pass-if "overwriting a top-level binding to a non-accessor" (pass-if "overwriting a top-level binding to a non-accessor"
(eval '(define (foo) #f) (current-module)) (eval '(define (foo) #f) (current-module))
(eval '(define-accessor foo) (current-module)) (eval '(define-accessor foo) (current-module))