# `Feel.Runtime.ResultType`
[🔗](https://github.com/FeeJai/BDM/blob/feel-v0.1.0/apps/feel/lib/feel/runtime/result_type.ex#L1)

The conversion of a result to the type that was declared for it (D-138).

When a decision gives its value to its variable, the value is converted to the type of the
variable by the implicit conversions of DMN 1.6, section 10.3.2.9.4, and then has to conform
to it. `Feel.Analysis.Analyzer` puts a `:conform` node around an expression that has a
declared type, and a backend calls `conform/4` with the value it got. It is a function of the
runtime, and not a part of a backend, because generated code may call only `Feel.Runtime` and
both backends have to give the same result.

  * `null` conforms to every type, and is the result as it is.
  * A value that conforms is the result. One that does after a conversion is converted
    (`Feel.Type.Conversion.convert/3`: conformance first, then a singleton list is unwrapped, a
    value is wrapped in a list, a date becomes a date and time), and the conversion is reported
    as an `:info` (`:implicit_conversion`, D-46), which does not end a strict run.
  * A value that cannot be made to conform is `null`, with an error (`:type_mismatch`) that
    ends a run in strict mode.

# `conform`

```elixir
@spec conform(
  Feel.Runtime.Env.t(),
  Feel.Value.t(),
  Feel.Type.t(),
  Feel.Diagnostic.span()
) ::
  {Feel.Value.t(), Feel.Runtime.Env.t()}
```

Converts a result to the declared type, found at `span`.

    iex> env = Feel.Runtime.Env.new()
    iex> {"a", converted_env} = Feel.Runtime.ResultType.conform(env, ["a"], :string, {0, 5})
    iex> for d <- Feel.Runtime.Env.diagnostics(converted_env), do: {d.severity, d.code, d.message}
    [{:info, :implicit_conversion, "the result is converted to the declared type string: a list with one element is replaced by that element"}]
    iex> {nil, ^env} = Feel.Runtime.ResultType.conform(env, nil, :string, {0, 5})
    iex> {nil, env} = Feel.Runtime.ResultType.conform(env, "a", :number, {0, 5})
    iex> [diagnostic] = Feel.Runtime.Env.diagnostics(env)
    iex> {diagnostic.code, diagnostic.message}
    {:type_mismatch, "the result is a string, which cannot be converted to the declared type number"}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
