Skip to content

Commit

Permalink
Manages functions shadowed by temporaries
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jan 16, 2025
1 parent c5cc572 commit 29c3780
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Famix-Python-Entities/FamixPythonLocalVariable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
|---|
| `declaredType` | `FamixTTypedEntity` | `typedEntities` | `FamixTType` | Type of the entity, if any|
| `receivingInvocations` | `FamixTInvocationsReceiver` | `receiver` | `FamixTInvocation` | List of invocations performed on this entity (considered as the receiver)|
| `shadowedEntity` | `FamixTShadower` | `shadowingEntities` | `FamixTShadowable` | Entity that is been shadowed by myself in my defining scope.|
| `shadowingEntities` | `FamixTShadowable` | `shadowedEntity` | `FamixTShadower` | Entities shadowing me in my defining scope.|
| `sourceAnchor` | `FamixTSourceEntity` | `element` | `FamixTSourceAnchor` | SourceAnchor entity linking to the original source code for this entity|
Expand All @@ -38,8 +40,8 @@
Class {
#name : 'FamixPythonLocalVariable',
#superclass : 'FamixPythonNamedEntity',
#traits : 'FamixTCanBeFinal + FamixTInvocationsReceiver + FamixTLocalVariable + FamixTWithComments',
#classTraits : 'FamixTCanBeFinal classTrait + FamixTInvocationsReceiver classTrait + FamixTLocalVariable classTrait + FamixTWithComments classTrait',
#traits : 'FamixTCanBeFinal + FamixTInvocationsReceiver + FamixTLocalVariable + FamixTShadowable + FamixTShadower + FamixTWithComments',
#classTraits : 'FamixTCanBeFinal classTrait + FamixTInvocationsReceiver classTrait + FamixTLocalVariable classTrait + FamixTShadowable classTrait + FamixTShadower classTrait + FamixTWithComments classTrait',
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
#tag : 'Entities'
Expand Down
2 changes: 2 additions & 0 deletions src/Famix-Python-Generator/FamixPythonGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ FamixPythonGenerator >> defineHierarchy [
localVariable --|> #TCanBeFinal.
localVariable --|> #TInvocationsReceiver.
localVariable --|> #TWithComments.
localVariable --|> #TShadowable.
localVariable --|> #TShadower.

method --|> containerEntity.
method --|> #TMethod.
Expand Down
25 changes: 25 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,31 @@ FamixPythonProject1Test >> testFunctionShadowedByGlobal [
print(14)' copyReplaceAll: String cr with: String lf)
]

{ #category : 'tests - shadowing' }
FamixPythonProject1Test >> testFunctionShadowedByTemporary [

| shadower shadowed |
shadower := self localVariableNamed: 'function_with_local_of_same_name'.
shadowed := self functionNamed: 'function_with_local_of_same_name'.

self assert: shadower name equals: 'function_with_local_of_same_name'.
self deny: shadower isShadowed.
self assert: shadower parentBehaviouralEntity equals: shadowed.
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadower sourceText equals: ('function_with_local_of_same_name' copyReplaceAll: String cr with: String lf).

self assert: shadowed name equals: 'function_with_local_of_same_name'.
self assert: shadowed isShadowed.
self assert: shadowed functionOwner equals: (self moduleNamed: 'moduleWithShadowing').
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadowed sourceText equals: ('def function_with_local_of_same_name(init):
if init > 10:
return init
function_with_local_of_same_name = init
return function_with_local_of_same_name + 3' copyReplaceAll: String cr with: String lf)
]

{ #category : 'tests - functions' }
FamixPythonProject1Test >> testFunctionSourceAnchor [

Expand Down

0 comments on commit 29c3780

Please sign in to comment.