diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2024-09-16 14:39:12 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2024-09-16 14:39:12 (GMT) |
commit | 1f9cd9ee4b823286b09669350d78b4428ad7bd83 (patch) | |
tree | 55674cef69cc3e24fc4f09d60ee549b6d82cb6db | |
parent | ccd91024213075307a8b1285eb9dfd374b14f09d (diff) | |
download | tcl-1f9cd9ee4b823286b09669350d78b4428ad7bd83.zip tcl-1f9cd9ee4b823286b09669350d78b4428ad7bd83.tar.gz tcl-1f9cd9ee4b823286b09669350d78b4428ad7bd83.tar.bz2 |
[680503]: Ensure we make the shadow delegate even if there is no argument to the class constructor.
-rw-r--r-- | generic/tclOOBasic.c | 13 | ||||
-rw-r--r-- | tests/ooUtil.test | 12 |
2 files changed, 23 insertions, 2 deletions
diff --git a/generic/tclOOBasic.c b/generic/tclOOBasic.c index 5f21203..5fab092 100644 --- a/generic/tclOOBasic.c +++ b/generic/tclOOBasic.c @@ -89,13 +89,14 @@ TclOO_Class_Constructor( Tcl_WrongNumArgs(interp, Tcl_ObjectContextSkippedArgs(context), objv, "?definitionScript?"); return TCL_ERROR; - } else if (objc == Tcl_ObjectContextSkippedArgs(context)) { - return TCL_OK; } /* * Make the class definition delegate. This is special; it doesn't reenter * here (and the class definition delegate doesn't run any constructors). + * + * This needs to be done before consideration of whether to pass the script + * argument to [oo::define]. [Bug 680503] */ nameObj = Tcl_NewStringObj(oPtr->namespacePtr->fullName, -1); @@ -105,6 +106,14 @@ TclOO_Class_Constructor( Tcl_DecrRefCount(nameObj); /* + * If there's nothing else to do, we're done. + */ + + if (objc == Tcl_ObjectContextSkippedArgs(context)) { + return TCL_OK; + } + + /* * Delegate to [oo::define] to do the work. */ diff --git a/tests/ooUtil.test b/tests/ooUtil.test index 9e1de8f..709089d 100644 --- a/tests/ooUtil.test +++ b/tests/ooUtil.test @@ -177,6 +177,18 @@ test ooUtil-1.9 {TIP 478: classmethod in safe child interp} -setup { } -cleanup { interp delete $safeinterp } -result {{::Table called with arguments: foo bar} {}} +test ooUtil-1.10.1 {Bug 680503: classmethod shouldn't require create body} -body { + oo::class create C + oo::define C {classmethod cm {} {}} +} -cleanup { + catch {C destroy} +} -result {} +test ooUtil-1.10.2 {Bug 680503: case that worked} -body { + oo::class create C {} + oo::define C {classmethod cm {} {}} +} -cleanup { + catch {C destroy} +} -result {} test ooUtil-2.1 {TIP 478: callback generation} -setup { oo::class create parent |