Skip to content

Commit a16c848

Browse files
committed
Fix PsiInvalidElementAccessException
1 parent bf7ffe0 commit a16c848

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/main/kotlin/org/arend/injection/InjectedArendEditor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ abstract class InjectedArendEditor(
386386
var scope: Scope? = null
387387
var ref: Referable? = null
388388
if (unresolvedRef != null || error.hasExpressions()) {
389-
scope = (data as? PsiElement)?.ancestor<ArendCompositeElement>()?.scope?.let { CachingScope.make(it) }
389+
val compositeElement = (data as? PsiElement)?.ancestor<ArendCompositeElement>()
390+
if (compositeElement?.isValid == true) scope = compositeElement.scope.let { CachingScope.make(it) }
390391
}
391392
if (unresolvedRef != null && scope != null) {
392393
ref = ExpressionResolveNameVisitor.resolve(unresolvedRef, scope)

src/main/kotlin/org/arend/psi/ext/ArendCompositeElement.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ interface ArendSourceNode: ArendCompositeElement, Abstract.SourceNode {
4747
}
4848

4949
fun getArendScope(element: ArendCompositeElement): Scope {
50+
if (!element.isValid)
51+
return EmptyScope.INSTANCE
5052
val sourceNode = element.ancestor<ArendSourceNode>()?.topmostEquivalentSourceNode ?: return (element.containingFile as? ArendFile)?.scope ?: EmptyScope.INSTANCE
5153
((sourceNode as? ArendLongName)?.parent as? ArendDocReference)?.let { return it.scope }
5254

0 commit comments

Comments
 (0)