Skip to content

Commit

Permalink
Fix importing proto when multiple includes define the same type in di…
Browse files Browse the repository at this point in the history
…fferent namespaces (#941)
  • Loading branch information
AriehSchneier authored Oct 2, 2024
1 parent f69d498 commit af08e60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Binary file modified internal/bundles/assets/import_proto_cli.arraiz
Binary file not shown.
11 changes: 9 additions & 2 deletions pkg/importer/proto/proto_to_sysl.arrai
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ let referencedType = \t \file \appName \imports \scope \prefix
# `referencedNs` finds the file that had the original type definition and returns the namespace of that file.
let referencedNs = \t \file \imports
let resolvedImports = (file.@value.imports => cond {includeImport(.@): resolveImport(.@, imports)}) where .;
let ref = (
let refs = (
(resolvedImports where fileContainsType(imports(.), t.name)) ||
# FIXME: this is a hack. Currently the proto importer has problems parsing types references which references
# nested types (types defined in a type). When this happens, imports cannot be resolved as it will not be
# able to find the referenced types in imported definitions. What this hack does is ensure that if a type
# is not found in imported definitions, it will attempt to find the type in the main file.
{file.@}
) single;
);
let refs = cond {
# If more than 1 file was found then also check the package (it should probably do that above already in fileContainsType)
refs count > 1: refs where //seq.has_prefix(getPackage((@value:imports(.))), t.package),
_: refs,
};
let _ = cond {refs count > 1: //error($`"${t}" found in multiple files: ${refs}`)};
let ref = refs single;
getNamespace(imports(ref));

let samePackage = \t t.package?:'' = getPackage(file);
Expand Down

0 comments on commit af08e60

Please sign in to comment.