[Top][All Lists]

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

[Help-smalltalk] variable scoping (was Re: compiling method attributes)

From: Stephen Compall
Subject: [Help-smalltalk] variable scoping (was Re: compiling method attributes)
Date: Sun, 31 Dec 2006 16:15:33 -0600

On Sun, 2006-12-31 at 18:19 +0100, Paolo Bonzini wrote:
> This one seems wrong, you need "self start + source size - 1" IMO?


> Except #primitive:, compilation of attributes is taken care by blocks 
> registered with the classes and returned by Class>>#pragmaHandlerFor: 
> (if it returns nil, the attribute has no compile-time semantics).  With 
> the usual bugs due to lack of good unit tests...
> The blocks are evaluated passing the CompiledMethod and the attribute (a 
> Message), and their return value is nil or an error message.

Well, this is better than ... reimplementing everything ...

> > (Wondering what's causing the "duplicate variable name" warnings.  Oh
> > well, some other time, more testing)
> I get them too, let's see who gets it first.

2006-12-31  Stephen Compall  <address@hidden>

        * compiler/ Support nested scopes, warn on
        variable shadowing, and raise compiler error if variable
        duplicated at same scope level.

The spurious 'duplicate variable name' warning was due to a boolean

While looking for that I found something else that seemed odd:

st> [UndefinedObject compile: 'scTest |a| a := 2. [:a | a] value. ^a']
        on: Warning
        do: [:w | w messageText printNl. w resume]!
'duplicate variable name a'
Object: STFileInParser new "<-0x4c24cba0>" error: Undefined variable 'a' 

I tested this in Squeak, which makes compilation fail for shadowing
names.  While this is just a change from compileWarning: to
compileError:, I decided to add variable scope-sensitivity and shadowing
instead, which seems to be what the builtin compiler does as well.

With this patch:

st> [UndefinedObject compile: 'scTest |a| a := 2. [:a | a] value. ^a']
        on: Warning
        do: [:w | w messageText printNl. w resume]!
'variable ''a'' shadows another'

> The attached patch may require some work to retrofit into your (patched) 
> 2.3 tree, but I will backport the entire set to my arch repository later.

I would love to be working with arch, but...see
<address@hidden>, or
'command-line-dependent compiler "error"' for more.

Stephen Compall

Attachment: signature.asc
Description: This is a digitally signed message part

reply via email to

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