Skip to content

Commit

Permalink
Final fix: convert Undeclared variables encoded as simple associatins…
Browse files Browse the repository at this point in the history
… to real variable objects.

Current bootstrap process use simple associations to represent vars in Undeclared registry. 
It breaks introduced logic here which explicitly return existing variable from Undeclared registry:
    - compiler parts expect kind of variable and not a simple association.
The bootstrap will be updated at some point. But now this case needs to be supported: 
  - declaring undefined var should update registered variable when it's type is not undeclared var
  • Loading branch information
dionisiydk committed Jun 16, 2020
1 parent 858d536 commit dbe8f19
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Kernel/UndeclaredVariable.class.st
Expand Up @@ -16,8 +16,16 @@ UndeclaredVariable class >> registeredWithName: aString [
| varName |
varName := aString asSymbol.

Undeclared add: (self named: varName).
^OCUndeclaredVariable new name: varName
Undeclared associationAt: varName ifPresent: [ :found |
found class == Association ifTrue: [
"Found undeclared var can be an association during current bootstrap process.
So here we should convert it to real variable object otherwise the build will be broken"
found becomeForward: (self named: varName)].
^found ].

^(self named: varName)
register;
yourself
]

{ #category : #OCVARIABLE }
Expand Down
22 changes: 22 additions & 0 deletions src/OpalCompiler-Tests/OCCompiledMethodIntegrityTest.class.st
Expand Up @@ -128,3 +128,25 @@ OCCompiledMethodIntegrityTest >> testUndeclaredVariableWhenItIsAlreadyRegistered
self assert: undeclaredBinding identicalTo: var.
undeclaredBinding unregister
]

{ #category : #test }
OCCompiledMethodIntegrityTest >> testUndeclaredVariableWhenItIsAlreadyRegisteredAsAssociation [
"Test describes current state of bootstrap where undeclared vars are encoded using associations.
It breaks introduced logic which explicitly return existing variable from Undeclared registry.
Compiler parts expect kind of variable and not a simple association.
The bootstrap will be updated at some point. But now this case needs to be supported:
- declaring undefined var should update registered variable when its type is not undeclared var"
| newCompiledMethod undeclaredBinding |
Undeclared add: #undeclaredTestVar -> nil.
newCompiledMethod := OpalCompiler new
source:
'methodWithUndeclaredVar
^ undeclaredTestVar';
class: OCMockCompilationClass;
compile.

undeclaredBinding := newCompiledMethod literals detect: [ :each | each name = #undeclaredTestVar ].
self assert: undeclaredBinding class equals: UndeclaredVariable.
self assert: undeclaredBinding identicalTo: (Undeclared associationAt: #undeclaredTestVar).
undeclaredBinding unregister
]

0 comments on commit dbe8f19

Please sign in to comment.