Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

fuzion/runtime/invariant_fault.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature invariant_fault
#
#  Author: Fridtjof Siebert (siebert@tokiwa.software)
#
# -----------------------------------------------------------------------

# invariant_fault -- effect that terminates a computation due to a failed
# condition in an invariant statement
#
public invariant_fault (
  # the handler this effect uses to fail
  p String -> void
  ) : eff.fallible p
is


  # default implementation of fuzion.runtime.invariant_fault
  #
  # this will get instated automatically at startup
  #
  public redef fixed type.default_value option fuzion.runtime.invariant_fault =>
    fuzion.runtime.invariant_fault msg->
      fuzion.runtime.contract_fault.cause ("inv", msg)


  # create an instance of `invariant_fault` with the given error handler.
  #
  public fixed redef type.new(h String -> void) fuzion.runtime.invariant_fault => fuzion.runtime.invariant_fault h


# invariant_fault with no argument returns invariant_fault.env, the currently installed
# runtime invariant_fault handler.
#
# NYI: CLEANUP: Remove and use `invariant_fault.env` directly.
#
public invariant_fault invariant_fault => invariant_fault.env


# cause an invariant fault with given msg argument, i.e., call invariant_fault.cause
# msg, i.e., use the current invariant_fault effect to fail with the given message.
#
public invariantcondition_fault(msg String) void => invariant_fault.cause msg

last changed: 2026-04-21