You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: validate.go
    path of file: ./repos/cerbos/internal/policy
    
    the code of the file until where you have to start completion: // Copyright 2021-2024 Zenauth Ltd.
// SPDX-License-Identifier: Apache-2.0

package policy

import (
	"errors"
	"fmt"

	policyv1 "github.com/cerbos/cerbos/api/genpb/cerbos/policy/v1"
	sourcev1 "github.com/cerbos/cerbos/api/genpb/cerbos/source/v1"
	"github.com/c
    
func validateDerivedRoles(dr *policyv1.DerivedRoles, sc parser.SourceCtx) (outErr error) {
	roleNames := make(map[string]int, len(dr.Definitions))
	for i, rd := range dr.Definitions {
		// Check for name clashes
		if idx, exists := roleNames[rd.Name]; exists {
			pos, context := sc.PositionAndContextForProtoPath(DerivedRoleRuleProtoPath(i))
			var msg string
			if prev := sc.PositionForProtoPath(DerivedRoleRuleProtoPath(idx - 1)); prev != nil {
				msg = fmt.Sprintf("duplicate derived role definition %q: definition #%d has the same name as definition #%d at %d:%d", rd.Name, i+1, idx, prev.GetLine(), prev.GetColumn())
			} else {
				msg = fmt.Sprintf("duplicate derived role definition %q: definition #%d has the same name as definition #%d", rd.Name, i+1, idx)
			}

			outErr = errors.Join(outErr, newValidationError(msg, pos, context))
		} else {
			roleNames[rd.Name] = i + 1
		}
	}

	return
}