diff --git a/interpreter/import_test.go b/interpreter/import_test.go index 6c8206b1a..c261b5656 100644 --- a/interpreter/import_test.go +++ b/interpreter/import_test.go @@ -446,7 +446,7 @@ func TestInterpretImportWithAlias(t *testing.T) { import a as a2 from 0x2 access(all) fun test(): Int { - return a() + a() + return a1() + a2() } `, ParseAndCheckOptions{ diff --git a/interpreter/interpreter_import.go b/interpreter/interpreter_import.go index 4d9296241..3d7f16983 100644 --- a/interpreter/interpreter_import.go +++ b/interpreter/interpreter_import.go @@ -32,13 +32,13 @@ func (interpreter *Interpreter) VisitImportDeclaration(declaration *ast.ImportDe resolvedLocations := interpreter.Program.Elaboration.ImportDeclarationsResolvedLocations(declaration) for _, resolvedLocation := range resolvedLocations { - interpreter.importResolvedLocation(resolvedLocation) + interpreter.importResolvedLocation(resolvedLocation, &declaration.Aliases) } return nil } -func (interpreter *Interpreter) importResolvedLocation(resolvedLocation sema.ResolvedLocation) { +func (interpreter *Interpreter) importResolvedLocation(resolvedLocation sema.ResolvedLocation, aliases *map[string]string) { config := interpreter.SharedState.Config // tracing @@ -62,7 +62,14 @@ func (interpreter *Interpreter) importResolvedLocation(resolvedLocation sema.Res if identifierLength > 0 { variables = make(map[string]Variable, identifierLength) for _, identifier := range resolvedLocation.Identifiers { - variables[identifier.Identifier] = + name := identifier.Identifier + alias, ok := (*aliases)[name] + if ok { + name = alias + } + + // map alias to original + variables[name] = subInterpreter.Globals.Get(identifier.Identifier) } } else {