Skip to content

Commit

Permalink
Fix undetected bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Feb 25, 2023
1 parent a095b3e commit 90ee51f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Chanel-Tests/ChanelRemoveUnecesaryNotCleanerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ ChanelRemoveUnecesaryNotCleanerTest >> testNotNot [
self assert: 'self test not not' isRewrittenAs: 'self test'
]

{ #category : #tests }
ChanelRemoveUnecesaryNotCleanerTest >> testRegression1 [
self denyIsRewritten: '| rewriter |
rewriter := self rewriter.
(self scope flatCollect: [ :class | class localMethods , class class localMethods ])
do: [ :method | (rewriter executeTree: method ast) ifTrue: [ method installAST ] ]'
]

{ #category : #tests }
ChanelRemoveUnecesaryNotCleanerTest >> testRejectNot [
self assert: '#() reject: [:e | e odd not ]' isRewrittenAs: '#() select: [:e | e odd ]'
Expand Down
10 changes: 6 additions & 4 deletions src/Chanel/RBVariableNode.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Extension { #name : #RBVariableNode }
RBVariableNode >> canBeUselessNode [
"This is an ugly hack.
Pharo AST has a bug to know if a temporary is a declaration or a usage. See https://github.com/pharo-project/pharo/issues/6277
This hack checks if the temporary is directly in its parent statements since declarations are not in the statements. In that case it's a candidate for removal."

self class environment at: #CopiedLocalVariable ifPresent: [ :c | (self variable isKindOf: c) ifTrue: [ ^ false ] ].
self isTempVariable ifTrue: [ ^ self parent statements includes: self ].

"If the parent of an arg is a method node, then it's probably the argument definition."
self isArgumentVariable ifTrue: [ ^ self parent isMethod not ].
self isArgumentVariable ifTrue: [ ^ self parent isMethod not ].

^ super canBeUselessNode
]

Expand Down

0 comments on commit 90ee51f

Please sign in to comment.