Detecting Variable Being Assined to Itself

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Detecting Variable Being Assined to Itself

Runar Jordahl
I came across this error in my code:

mySetter: aNumber
        number := number

As you can see, the argument (aNumber) is not used. Instead the
instance variable (number) is set to itself.

Is there any way to detect the assignment of one variable to itself? A
Lint rule or rewrite rule (just the query) would be great to have.

I am not looking for a rule to detect that an argument is not used. In
many cases this is perfectly OK.

Kind regards
Runar
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Detecting Variable Being Assined to Itself

davidbuck
This rewrite rule will at least find it:

    `@var := `@var

David Buck

Runar Jordahl wrote:
I came across this error in my code:

mySetter: aNumber
	number := number

As you can see, the argument (aNumber) is not used. Instead the
instance variable (number) is set to itself.

Is there any way to detect the assignment of one variable to itself? A
Lint rule or rewrite rule (just the query) would be great to have.

I am not looking for a rule to detect that an argument is not used. In
many cases this is perfectly OK.

Kind regards
Runar
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.801 / Virus Database: 271.1.1/2827 - Release Date: 04/21/10 14:31:00


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Detecting Variable Being Assined to Itself

John Brant-2
In reply to this post by Runar Jordahl
On 4/22/2010 6:15 AM, Runar Jordahl wrote:

> I came across this error in my code:
>
> mySetter: aNumber
> number := number
>
> As you can see, the argument (aNumber) is not used. Instead the
> instance variable (number) is set to itself.
>
> Is there any way to detect the assignment of one variable to itself? A
> Lint rule or rewrite rule (just the query) would be great to have.

You can use this rewrite rule:
        `var := `var

If you want a lint rule, you can add:

ParseTreeLintRule class>>variableAssignedToItself
        ^self
                createParseTreeRule: #('`var := `var')
                name: 'Variable assigned to itself'


John Brant
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Detecting Variable Being Assined to Itself

Runar Jordahl
Thanks to all of you. The answer was too simple for me to discover. :-)

Runar
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc