-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix importing proto when multiple includes define the same type in di…
…fferent namespaces (#941)
- Loading branch information
1 parent
f69d498
commit af08e60
Showing
2 changed files
with
9 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = ([email protected] => 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); | ||
|