Skip to content

Commit 50c090f

Browse files
JMLFguillep
authored andcommitted
Raise a better exception with contextual information
1 parent d230dbb commit 50c090f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/OpalCompiler-Core/OCAbstractMethodScope.class.st

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ OCAbstractMethodScope >> localTemps [
143143
OCAbstractMethodScope >> lookupDefiningContextForVariable: var startingFrom: aContext [
144144
"Is this the definition context for var? If it not, we look in the outer context using the corresponding outer scope. If found, we return the context"
145145

146+
| nextContext |
147+
nextContext := self nextOuterScopeContextOf: aContext.
148+
nextContext ifNil: [ self error: var name, ' optimized out' ].
146149
^self = var scope
147-
ifFalse: [ self outerScope lookupDefiningContextForVariable: var startingFrom: (self nextOuterScopeContextOf: aContext) ]
150+
ifFalse: [ self outerScope lookupDefiningContextForVariable: var startingFrom: nextContext ]
148151
ifTrue: [ aContext ]
149152
]
150153

src/OpalCompiler-Core/OCBlockScope.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ OCBlockScope >> nextOuterScopeContextOf: aContext [
4141
"Returns the next context to lookup a variable name from within outer scope.
4242
If it is block context then we return outer context for lookup.
4343
But if it is method context lookup will continue in same context but within outer scope"
44-
^ aContext outerContext ifNil: [ self error: 'OuterContext is not available' ]
44+
^ aContext outerContext
4545
]

0 commit comments

Comments
 (0)