Skip to content

Commit

Permalink
Check for invalidated resource in expression getter-setter
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Apr 2, 2024
1 parent f03315d commit 68f0aa5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions runtime/interpreter/interpreter_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ func (interpreter *Interpreter) typeIndexExpressionGetterSetter(
return getterSetter{
target: target,
get: func(_ bool) Value {
interpreter.checkInvalidatedResourceOrResourceReference(target, indexExpression)
return target.GetTypeKey(interpreter, locationRange, attachmentType)
},
set: func(_ Value) {
interpreter.checkInvalidatedResourceOrResourceReference(target, indexExpression)
// writing to composites with indexing syntax is not supported
panic(errors.NewUnreachableError())
},
Expand Down Expand Up @@ -194,12 +196,14 @@ func (interpreter *Interpreter) valueIndexExpressionGetterSetter(

if isNestedResourceMove {
get = func(_ bool) Value {
interpreter.checkInvalidatedResourceOrResourceReference(target, targetExpression)
value := target.RemoveKey(interpreter, locationRange, transferredIndexingValue)
target.InsertKey(interpreter, locationRange, transferredIndexingValue, placeholder)
return value
}
} else {
get = func(_ bool) Value {
interpreter.checkInvalidatedResourceOrResourceReference(target, targetExpression)
value := target.GetKey(interpreter, locationRange, transferredIndexingValue)

// If the indexing value is a reference, then return a reference for the resulting value.
Expand All @@ -211,6 +215,7 @@ func (interpreter *Interpreter) valueIndexExpressionGetterSetter(
target: target,
get: get,
set: func(value Value) {
interpreter.checkInvalidatedResourceOrResourceReference(target, targetExpression)
target.SetKey(interpreter, locationRange, transferredIndexingValue, value)
},
}
Expand Down Expand Up @@ -348,6 +353,9 @@ func (interpreter *Interpreter) checkMemberAccess(
target Value,
locationRange LocationRange,
) {

interpreter.checkInvalidatedResourceOrResourceReference(target, memberExpression)

memberInfo, _ := interpreter.Program.Elaboration.MemberExpressionMemberAccessInfo(memberExpression)
expectedType := memberInfo.AccessedType

Expand Down

0 comments on commit 68f0aa5

Please sign in to comment.