From aec26da4e68305fe4b69b2a78261904fd56e8417 Mon Sep 17 00:00:00 2001 From: prpr19xx <> Date: Sat, 3 Feb 2024 11:08:13 +0000 Subject: [PATCH 1/2] Allow selectable backwards compatibility for invalid variables --- oo.tcl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/oo.tcl b/oo.tcl index 4fefa9cc..96fca140 100644 --- a/oo.tcl +++ b/oo.tcl @@ -1,4 +1,5 @@ # OO support for Jim Tcl, with multiple inheritance +set ::oo::ignore_invalid_vars false # Create a new class $classname, with the given # dictionary as class variables. These are the initial @@ -81,11 +82,14 @@ proc class {classname {baseclasses {}} classvars} { $classname method defaultconstructor {{__vars {}}} { set __classvars [$self classvars] foreach __v [dict keys $__vars] { - if {![dict exists $__classvars $__v]} { - # level 3 because defaultconstructor is called by new - return -code error -level 3 "[lindex [info level 0] 0], $__v is not a class variable" + if {[dict exists $__classvars $__v]} { + set $__v [dict get $__vars $__v] + } else { + if {!$::oo::ignore_invalid_vars} { + # level 3 because defaultconstructor is called by new + return -code error -level 3 "[lindex [info level 0] 0], $__v is not a class variable" + } } - set $__v [dict get $__vars $__v] } } alias "$classname constructor" "$classname defaultconstructor" From 90adb6a8f135f690b9905d3c94d27afab1765b86 Mon Sep 17 00:00:00 2001 From: prpr19xx <> Date: Sat, 3 Feb 2024 11:08:13 +0000 Subject: [PATCH 2/2] Allow selectable backwards compatibility for invalid variables --- oo.tcl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/oo.tcl b/oo.tcl index 4fefa9cc..96fca140 100644 --- a/oo.tcl +++ b/oo.tcl @@ -1,4 +1,5 @@ # OO support for Jim Tcl, with multiple inheritance +set ::oo::ignore_invalid_vars false # Create a new class $classname, with the given # dictionary as class variables. These are the initial @@ -81,11 +82,14 @@ proc class {classname {baseclasses {}} classvars} { $classname method defaultconstructor {{__vars {}}} { set __classvars [$self classvars] foreach __v [dict keys $__vars] { - if {![dict exists $__classvars $__v]} { - # level 3 because defaultconstructor is called by new - return -code error -level 3 "[lindex [info level 0] 0], $__v is not a class variable" + if {[dict exists $__classvars $__v]} { + set $__v [dict get $__vars $__v] + } else { + if {!$::oo::ignore_invalid_vars} { + # level 3 because defaultconstructor is called by new + return -code error -level 3 "[lindex [info level 0] 0], $__v is not a class variable" + } } - set $__v [dict get $__vars $__v] } } alias "$classname constructor" "$classname defaultconstructor"