Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selectable backwards compatibility for invalid variables #294

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions oo.tcl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading