Skip to content

Commit ceb023e

Browse files
committed
[91b3a5bb14] msgcat method: same changes as in branch "ticket-91b3a5bb14-msgcat-oo-method", but based on core-8-branch
1 parent a1bb7d4 commit ceb023e

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

library/msgcat/msgcat.tcl

+19-18
Original file line numberDiff line numberDiff line change
@@ -1226,28 +1226,29 @@ proc ::msgcat::PackageNamespaceGet {} {
12261226
# Not in object environment
12271227
return $ns
12281228
}
1229-
1230-
# Check self namespace to determine environment
1231-
switch -exact -- [uplevel 2 { namespace which -command self }] {
1232-
{::oo::define::self} {
1233-
# We are within a class definition
1234-
return [namespace qualifiers [uplevel 2 { self }]]
1235-
}
1236-
{::oo::Helpers::self} {
1237-
# We are within an object
1238-
set Class [info object class [uplevel 2 { self }]]
1239-
# Check for classless defined object
1240-
if {$Class eq {::oo::object}} {
1229+
# Ticket 91b3a5bb14: call to self may fail if namespace is stored
1230+
# so catch all this
1231+
try {
1232+
# Check self namespace to determine environment
1233+
switch -exact -- [uplevel 2 { namespace which -command self }] {
1234+
{::oo::define::self} {
1235+
# We are within a class definition
12411236
return [namespace qualifiers [uplevel 2 { self }]]
12421237
}
1243-
# Class defined object
1244-
return [namespace qualifiers $Class]
1245-
}
1246-
default {
1247-
# Not in object environment
1248-
return $ns
1238+
{::oo::Helpers::self} {
1239+
# We are within an object
1240+
set Class [info object class [uplevel 2 { self }]]
1241+
# Check for classless defined object
1242+
if {$Class eq {::oo::object}} {
1243+
return [namespace qualifiers [uplevel 2 { self }]]
1244+
}
1245+
# Class defined object
1246+
return [namespace qualifiers $Class]
1247+
}
12491248
}
1249+
} on error {} {
12501250
}
1251+
return $ns
12511252
}
12521253

12531254
# Initialize the default locale

tests/msgcat.test

+24
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,30 @@ if {[package vsatisfies [package provide msgcat] 1.7]} {
12361236
bar::ObjCur method1
12371237
} -result con2baz
12381238

1239+
# HaO 2024-07-15 fix me
1240+
# Ticket 91b3a5bb: I have no idea what the following case should do.
1241+
# But currently, it raises an error and that should not happen.
1242+
# The background is the tklib tooltip package.
1243+
# This package captures the caller namespace to later invoke msgcat with current data.
1244+
# If the caller namespace is a method, it currently fails.
1245+
test msgcat-15.5 {ticket 91b3a5bb: method namespace recorded and evaluated gives error}\
1246+
-setup {
1247+
oo::class create App {}
1248+
oo::define App {
1249+
constructor {} { my add_one }
1250+
method add_one {} { recordMsgcat }
1251+
}
1252+
proc ::recordMsgcat {} { set ::nscaller [uplevel 1 {namespace current}] }
1253+
set application [App new]
1254+
} -cleanup {
1255+
$application destroy
1256+
App destroy
1257+
unset -nocomplain ::nscaller
1258+
rename ::recordMsgcat ""
1259+
} -body {
1260+
namespace eval $::nscaller [list ::msgcat::mc "Test"]
1261+
} -returnCodes ok -result Test
1262+
12391263
# Test msgcat-16.*: command mcpackagenamespaceget
12401264

12411265
test msgcat-16.1 {mcpackagenamespaceget in namespace procedure} -body {

0 commit comments

Comments
 (0)