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: check_layer_field_names.m
    path of file: ./repos/GAN-Base-on-Matlab/layer
    
    the code of the file until where you have to start completion: function check_layer_field_names(layer, required_fields, optional_fields)
    for i = 1:numel(required_fields)
        field_name = required_fields{i};
        if ~isfield(layer, field_name)
            error([field_name, ' is required in ', layer.type])
        end
    end
    current_field_names = fieldnames(layer);

    
function check_layer_field_names(layer, required_fields, optional_fields)
    for i = 1:numel(required_fields)
        field_name = required_fields{i};
        if ~isfield(layer, field_name)
            error([field_name, ' is required in ', layer.type])
        end
    end
    current_field_names = fieldnames(layer);
    for i = 1:numel(current_field_names)
        current_field = current_field_names{i};
        if ~ismember(current_field, [required_fields, optional_fields])
            error(['redundant filed in ', layer.type, ':', current_field])
        end