Hi Milan, On Mon, Mar 19, 2012 at 11:22 AM, Milan Mimica <milan.mimica@gmail.com>wrote:
On 18 March 2012 23:20, Guillermo Polito <guillermopolito@gmail.com>wrote:
Hmm, you can compile a method with Behavior>>#compile:notifying:
and send an observer implementing:
#notify:at:in:
and some other stuff like #selection #deselect...
That way you can capture the errors...
This almost works. It doesn't raise errors for undeclared variables, instead it prompts for variable replacement.
| method requestor | requestor := Mock new. (requestor stub: #selectionInterval) returns: (1 to: 2). requestor stub: #selectFrom:to:. (requestor stub: #bindingOf:) returns: nil. (requestor stub: #notify:at:in:) will: [ self halt ]. method := Compiler new compiledMethodFor: 'a:=1' in: nil to: nil notifying: requestor proxy ifFail: nil logged: false. method inspect
I would like to catch the error. It is an error, right?
the answer is "not necessarily". Smalltalk deals with circular references between globals in source by using Undeclared. So if the source of class A references class B and vice verse, and they are filed-in one after another, when class A's source is compiled, a reference to B will be created in undeclared. When B's source is compiled, that Undeclared binding will be moved to Smalltalk and updated to reference class B. So one could say in non-interactive use a) compiling source containing an undeclared reference merits only a warning b) compiling source containiing an undeclared reference in the form of a variable beginning with lower-case is an error, since globals should be capitalized c) force classes to be defined before their source is compiled IMO, it's not an error, and a) is a good option. Note that if you did make it an error in all circumstances you'd badly break the system. --
Milan Mimica
-- HTH, Eliot