function mustBeCompatibleReferenceStruct(X, Y)
% MUSTBECOMPATIBLEREFERENCESTRUCT checks if X is a struct with a type '()'
% and that it has the same number of points as Y variables

%   Copyright 2019 The MathWorks, Inc.
    if length(X) > 1
        throw(createValidatorException(message('symbolic:sym:NestedIndex')));
    end

    if ~strcmp(X.type, '()')
        throw(createValidatorException(message('symbolic:symfun:Indexing')));
    end

    Yvars = argnames(Y);
    inds = X.subs;
    if length(inds) ~= length(Yvars)
        throw(createValidatorException(message('symbolic:symfun:subsref', length(Yvars), length(inds))));
    end

    strs = cellfun(@ischar, inds);
    if any(strcmp(inds(strs), ':'))
        throw(createValidatorException(message('symbolic:symfun:subsrefColon')));
    end
end

function E = createValidatorException(messageObject, varargin)
    E = MException(messageObject.Identifier, messageObject.getString);
end