From af08e603ebb4818f2aa820f7a978a6f798bcc6c3 Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:29:51 +1000 Subject: [PATCH] Fix importing proto when multiple includes define the same type in different namespaces (#941) --- .../bundles/assets/import_proto_cli.arraiz | Bin 39017 -> 39147 bytes pkg/importer/proto/proto_to_sysl.arrai | 11 +++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/bundles/assets/import_proto_cli.arraiz b/internal/bundles/assets/import_proto_cli.arraiz index 61d30c7ed126b98c2bb331c54a083a14c8283aa9..9c8119d8d2cbb6559ee5fb5f633f07630afb29de 100644 GIT binary patch delta 5116 zcmVFaaP^aWcvPV*$4+_Z70aj$n% zXDo<>EXEYU0+16uvhK6r?BWjrigMy6b8~l7y^#oFv5Up-54-rInrle%Yp!3h6;~}Q z_yq9rXI9*>YkXi$BVI_cI&XC)nxNpBSgm-YCy-Z7QLjt>a@7inf6ogc-!WOfu9;f$ z@@J-(6UeeGg(;kzY_pTKuIk;lj|}ftR;x-^x5!IxTK)@POdwYqRljBnj$%z9FW8FL z&zR!K_;tf>I6j1}p0qdDClyJ+C2>%m1#4Su=R!O+KYrp$na;ILYURuK+GA3(>O>1s zs}t6?4O?;FsO06ke~3t~E4^ILvqG$p@GDkX`a(2XR`a;qk~bxn7n_#E+9& zt{VQdX~Y3RP$^#-LN4j)Y9-1mSArdWbOaYm4r;wvRPR9xU}cG4ddY#cZCw=%hY_$V zAQpS&ddV~_MO`Yu!2s3rqFUIuDkI_X#nZNZZFo#!guPHBe_}psjp2|^XHbadmP@UG zfqel=%c{91(cqTVRT=R&Z-a(rBw|cVQiP0P3YV_R$%*2BWNJN6M%icrqpQ)x)lH3v zk}FZ)T63L&;!GAxu87fMUDvRvYGkRG3aSQX#;Vi|7D9q(xKYxIX-}n=LTWJeh%iGw zm1Tf6f_K0ae^eTK&6y+)3|c9)Aie>mngN3qYjK>I6^rU)gD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1j8^uRlzov5sLQDuWlSm-f`<%Gs^m3;SqV?KjG&5M@KJTBoO-u(f)#_u&+-dpajB ze_eFJ&xXj&=I?_$KZG>f4(;)2+tc<9?aEN@0T0h04)amB&tf;QdQWYqr?7drcPUXj z{gX4dBNc+4AJ=;$D!{K7b**L|Qj|lH@GjwvefvO<`_+(__i^co{%!V?j4tlA>aKA( zW18BI(wGN(Ksz_hEkQ8OwST3v`y>b2e=KUxtJn4)4?wUUYhT&!f4vj5_3sA;&bO01ScoGRL%8aixxbP9y;kkk~y$F^Kfhqv>c$NIG6_Bvk0FuY_^kd zRQI|NcsGJJhuAfI-@^6FhX2;NIvj@+c+A|>FcR*Lc0y}wn`IrJw&~pNb|y_Te+-TD z&_Ju+2uvOv0e>+4qOR>3ExFjt`>=8cJ1dd%(!Nl){z<+$?7HNUW~)yNdcnwZyAy4D zVh$fk8oF@woH9*yDPDb`TqnhurGJDnfcnzBoI`jCVg#$}4%+h%h0+K#^lD4_9B^#MrN^H&1Lk4XpS0e-`wcrp~M{+JY{fHEvHwzwMMGng87-3vyLY>dON1 zPMPNr+gJ3#0?iH$S?#v_+;HF@h9qb3)py1v+Xg2$H=$ilB)_{kY4^5h zGmBJ?Qe&L)!G8q+0RR6`O9u!!CRph45&!@uNt3`E9Fr~`D3cJE53}NeUla;CCRph4 q5&!@uNs~*LgaHqe(3ffgr-hTzmoJlRm^A@IlcAVI1`Uz`0002Q=Cxb^ diff --git a/pkg/importer/proto/proto_to_sysl.arrai b/pkg/importer/proto/proto_to_sysl.arrai index 40c04a2c..3acf5ed0 100644 --- a/pkg/importer/proto/proto_to_sysl.arrai +++ b/pkg/importer/proto/proto_to_sysl.arrai @@ -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);