module T::Private::Methods::SignatureValidation

def self.validate_non_override_mode(signature)

def self.validate_non_override_mode(signature)
  case signature.mode
  when Modes.override
    if signature.method_name == :each && signature.method.owner < Enumerable
      # Enumerable#each is the only method in Sorbet's RBI payload that defines an abstract method.
      # Enumerable#each does not actually exist at runtime, but it is required to be implemented by
      # any class which includes Enumerable. We want to declare Enumerable#each as abstract so that
      # people can call it anything which implements the Enumerable interface, and so that it's a
      # static error to forget to implement it.
      #
      # This is a one-off hack, and we should think carefully before adding more methods here.
      nil
    else
      raise "You marked `#{signature.method_name}` as #{pretty_mode(signature)}, but that method doesn't already exist in this class/module to be overriden.\n" \
        "  Either check for typos and for missing includes or super classes to make the parent method shows up\n" \
        "  ... or remove #{pretty_mode(signature)} here: #{method_loc_str(signature.method)}\n"
    end
  when Modes.standard, *Modes::NON_OVERRIDE_MODES
    # Peaceful
    nil
  else
    raise "Unexpected mode: #{signature.mode}. Please report to #dev-productivity."
  end
  owner = signature.method.owner
  if (signature.mode == Modes.abstract || Modes::OVERRIDABLE_MODES.include?(signature.mode)) &&
      owner.singleton_class?
    # Given a singleton class, we can check if it belongs to a
    # module by looking at its superclass; given `module M`,
    # `M.singleton_class.superclass == Module`, which is not true
    # for any class.
    if owner.superclass == Module
      raise "Defining an overridable class method (via #{pretty_mode(signature)}) " \
            "on a module is not allowed. Class methods on " \
            "modules do not get inherited and thus cannot be overridden. For help, ask in " \
            "#dev-productivity."
    end
  end
end