Skip to content

Commit

Permalink
add support for injecting composite types, potentially nested: perfor…
Browse files Browse the repository at this point in the history
…m lookup in base type activation
  • Loading branch information
turbolent committed Sep 22, 2023
1 parent 7cb1074 commit 957de13
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 64 deletions.
15 changes: 14 additions & 1 deletion runtime/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,21 @@ func (e *interpreterEnvironment) newImportLocationHandler() interpreter.ImportLo

func (e *interpreterEnvironment) newCompositeTypeHandler() interpreter.CompositeTypeHandlerFunc {
return func(location common.Location, typeID common.TypeID) *sema.CompositeType {
if _, ok := location.(stdlib.FlowLocation); ok {

switch location.(type) {
case stdlib.FlowLocation:
return stdlib.FlowEventTypes[typeID]

case nil:
qualifiedIdentifier := string(typeID)
ty := sema.TypeActivationNestedType(e.baseTypeActivation, qualifiedIdentifier)
if ty == nil {
return nil
}

if compositeType, ok := ty.(*sema.CompositeType); ok {
return compositeType
}
}

return nil
Expand Down
18 changes: 10 additions & 8 deletions runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4796,16 +4796,18 @@ func (interpreter *Interpreter) GetCompositeType(
if compositeType != nil {
return compositeType, nil
}
} else {
config := interpreter.SharedState.Config
compositeTypeHandler := config.CompositeTypeHandler
if compositeTypeHandler != nil {
compositeType = compositeTypeHandler(location, typeID)
if compositeType != nil {
return compositeType, nil
}
}

config := interpreter.SharedState.Config
compositeTypeHandler := config.CompositeTypeHandler
if compositeTypeHandler != nil {
compositeType = compositeTypeHandler(location, typeID)
if compositeType != nil {
return compositeType, nil
}
}

if location != nil {
compositeType = interpreter.getUserCompositeType(location, typeID)
if compositeType != nil {
return compositeType, nil
Expand Down
Loading

0 comments on commit 957de13

Please sign in to comment.