From: Mark Wooding Date: Sat, 3 Aug 2019 14:56:10 +0000 (+0100) Subject: src/builtin.lisp: Keep the first initarg in the list. X-Git-Url: https://git.distorted.org.uk/~mdw/sod/commitdiff_plain/dea6ee94a659dbe4794fa450037664781009d4eb src/builtin.lisp: Keep the first initarg in the list. Otherwise a superclass unexpectedly defining an initarg will cause it to be demoted relative to other initargs. --- diff --git a/src/builtin.lisp b/src/builtin.lisp index 08ad5f0..d07f539 100644 --- a/src/builtin.lisp +++ b/src/builtin.lisp @@ -434,7 +434,8 @@ static const SodClass *const ~A__cpl[] = { (dolist (initarg (reverse (remove-duplicates initargs :key #'sod-initarg-name - :test #'string=))) + :test #'string= + :from-end t))) (let ((arg-name (sod-initarg-name initarg))) (setf initinst (make-if-inst (format nil "suppliedp.~A" arg-name) diff --git a/test/test.sod b/test/test.sod index 47e8545..ee74da3 100644 --- a/test/test.sod +++ b/test/test.sod @@ -256,11 +256,20 @@ code c: tests { [link = SodObject, nick = t2] class T2: SodObject { [initarg = x] int x = 0; + [initarg = z] t2.x; initarg int y = 1; init { if (!y) STEP(0); } } +[link = T2] +class T2Sub: T2 { + [initarg = a] t2.x; + [initarg = b] t2.x; + [initarg = x] t2.x; + [initarg = c] t2.x; +} + code c: tests { prepare("initargs, defaults"); { SOD_DECL(T2, t, NO_KWARGS); @@ -272,6 +281,21 @@ code c: tests { if (t->t2.x == 42) STEP(1); DONE(2); } + prepare("initargs, inheritance"); + { SOD_DECL(T2Sub, t, KWARGS(K(c, 1) K(z, 2))); + if (t->t2.x == 1) STEP(0); + DONE(1); + } + prepare("initargs, ordering"); + { SOD_DECL(T2Sub, t, KWARGS(K(a, 1) K(b, 2))); + if (t->t2.x == 1) STEP(0); + DONE(1); + } + prepare("initargs, reprioritizing"); + { SOD_DECL(T2Sub, t, KWARGS(K(x, 1) K(c, 2))); + if (t->t2.x == 1) STEP(0); + DONE(1); + } } /*----- Keyword argument propagation --------------------------------------*/