From 9f7a56d276ab355dcef962738ff8593d91472e4b Mon Sep 17 00:00:00 2001 From: ktec Date: Fri, 16 Oct 2020 13:25:28 +0100 Subject: [PATCH] Update Checker - add support for annotated types --- lib/rtypes/checker.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/rtypes/checker.ex b/lib/rtypes/checker.ex index c6532b7..1042479 100644 --- a/lib/rtypes/checker.ex +++ b/lib/rtypes/checker.ex @@ -286,6 +286,21 @@ defmodule RTypes.Checker do end) end + ## annotations + defp check(term, {:ann_type, _, [{:var, _, annotation}, typ]}, ctx) do + case check(term, typ, ctx) do + :ok -> + :ok + + {:error, _} -> + {:error, + term: term, + message: "term does not match annotated #{annotation} type", + types: typ, + ctx: ctx} + end + end + ## fall-through clause defp check(term, typ, ctx) do {:error, term: term, message: "term does not conform to type", types: [typ], ctx: ctx}