@@ -95,6 +95,10 @@ func translate(tctx *translationContext, root *dslNode) (*CompiledSchema, error)
9595 return nil , topLevelNode .WithSourceErrorf (name , "found name reused between multiple definitions and/or caveats: %s" , name )
9696 }
9797
98+ if _ , found := tctx .compiledPartials [name ]; found {
99+ return nil , topLevelNode .WithSourceErrorf (name , "found caveat with same name as existing partial: %s" , name )
100+ }
101+
98102 orderedDefinitions = append (orderedDefinitions , def )
99103
100104 case dslshape .NodeTypeDefinition :
@@ -111,6 +115,10 @@ func translate(tctx *translationContext, root *dslNode) (*CompiledSchema, error)
111115 return nil , topLevelNode .WithSourceErrorf (name , "found name reused between multiple definitions and/or caveats: %s" , name )
112116 }
113117
118+ if _ , found := tctx .compiledPartials [name ]; found {
119+ return nil , topLevelNode .WithSourceErrorf (name , "found definition with same name as existing partial: %s" , name )
120+ }
121+
114122 orderedDefinitions = append (orderedDefinitions , def )
115123 }
116124 }
@@ -864,6 +872,11 @@ func translatePartial(tctx *translationContext, partialNode *dslNode) error {
864872 if err != nil {
865873 return err
866874 }
875+ // Use the prefixed path to align with namespace and definition compilation
876+ partialPath , err := tctx .prefixedPath (partialName )
877+ if err != nil {
878+ return err
879+ }
867880 // This needs to return the unresolved name.
868881 errorOnMissingReference := false
869882 relationsAndPermissions , unresolvedPartial , err := translateRelationsAndPermissions (tctx , partialNode , errorOnMissingReference )
@@ -875,22 +888,22 @@ func translatePartial(tctx *translationContext, partialNode *dslNode) error {
875888 return nil
876889 }
877890
878- tctx .compiledPartials [partialName ] = relationsAndPermissions
891+ tctx .compiledPartials [partialPath ] = relationsAndPermissions
879892
880893 // Since we've successfully compiled a partial, check the unresolved partials to see if any other partial was
881894 // waiting on this partial
882895 // NOTE: we're making an assumption here that a partial can't end up back in the same
883896 // list of unresolved partials - if it hangs again in a different spot, it will end up in a different
884897 // list of unresolved partials.
885- waitingPartials , _ := tctx .unresolvedPartials .Get (partialName )
898+ waitingPartials , _ := tctx .unresolvedPartials .Get (partialPath )
886899 for _ , waitingPartialNode := range waitingPartials {
887900 err := translatePartial (tctx , waitingPartialNode )
888901 if err != nil {
889902 return err
890903 }
891904 }
892905 // Clear out this partial's key from the unresolved partials if it's not already empty.
893- tctx .unresolvedPartials .RemoveKey (partialName )
906+ tctx .unresolvedPartials .RemoveKey (partialPath )
894907 return nil
895908}
896909
@@ -902,14 +915,18 @@ func translatePartialReference(tctx *translationContext, partialReferenceNode *d
902915 if err != nil {
903916 return nil , "" , err
904917 }
905- relationsAndPermissions , ok := tctx .compiledPartials [name ]
918+ path , err := tctx .prefixedPath (name )
919+ if err != nil {
920+ return nil , "" , err
921+ }
922+ relationsAndPermissions , ok := tctx .compiledPartials [path ]
906923 if ! ok {
907924 if errorOnMissingReference {
908- return nil , "" , partialReferenceNode .Errorf ("could not find partial reference with name %s" , name )
925+ return nil , "" , partialReferenceNode .Errorf ("could not find partial reference with name %s" , path )
909926 }
910927 // If the partial isn't present and we're not throwing an error, we return the name of the missing partial
911928 // This behavior supports partial collection
912- return nil , name , nil
929+ return nil , path , nil
913930 }
914931 return relationsAndPermissions , "" , nil
915932}
0 commit comments