help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Namespace current: aSymbol


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Namespace current: aSymbol
Date: Fri, 08 Sep 2006 09:22:49 +0200
User-agent: Thunderbird 1.5.0.5 (Macintosh/20060719)


The primitive for Namespace class>>#current: appears to ignore its
argument if it is not a Dictionary or Class.  Perhaps the Smalltalk
code that follows it should do the same, or signal an error of some
kind, if aNamespaceOrClass is not in fact a BindingDictionary (or
Dictionary) or Class?
Yep, as in the attached patch.

Paolo
--- orig/kernel/Builtins.st
+++ mod/kernel/Builtins.st
@@ -2585,10 +2585,18 @@ current: aNamespaceOrClass
     "Set the current namespace to be aNamespace or, if it is a class,
      its class pool (the Dictionary that holds class variables)."
     "The primitive call is needed to inform the compiler"
+    | namespace |
     <primitive: VMpr_Namespace_setCurrent>
-    Current := aNamespaceOrClass isClass
+    namespace := aNamespaceOrClass isClass
        ifTrue: [ aNamespaceOrClass classPool ]
        ifFalse: [ aNamespaceOrClass ].
+
+    (namespace isKindOf: Dictionary)
+       ifTrue: [ Current := namespace ]
+       ifFalse: [
+           SystemExceptions.WrongClass
+               signalOn: aNamespaceOrClass
+               mustBe: { Dictionary. Class } ].
 ! !
 
 
--- orig/kernel/AnsiExcept.st
+++ mod/kernel/AnsiExcept.st
@@ -1083,14 +1083,16 @@ validClassesString
     "Answer the list of classes whose instances would have been valid,
     formatted as a string."
     ^String streamContents: [ :str |
-       validClasses keysAndValuesDo: [ :idx :binding |
+       validClasses keysAndValuesDo: [ :idx :classOrBinding |
            | name class |
            idx > 1 ifTrue: [
                idx = validClasses size
                    ifFalse: [ str nextPutAll: ', ' ]
                    ifTrue: [ str nextPutAll: ' or ' ]
            ].
-           class := binding value.
+           class := classOrBinding isClass
+               ifTrue: [ classOrBinding ]
+               ifFalse: [ classOrBinding value ].
            name := class nameIn: Namespace current.
            name first isVowel
                ifTrue: [ str nextPutAll: 'an ' ]

reply via email to

[Prev in Thread] Current Thread [Next in Thread]