aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lux/analyser/case.clj19
-rw-r--r--src/lux/analyser/lux.clj2
-rw-r--r--src/lux/type.clj14
3 files changed, 15 insertions, 20 deletions
diff --git a/src/lux/analyser/case.clj b/src/lux/analyser/case.clj
index 5d6bc9965..1c315e405 100644
--- a/src/lux/analyser/case.clj
+++ b/src/lux/analyser/case.clj
@@ -37,7 +37,7 @@
("VariantTestAC" 1))
;; [Utils]
-(def ^:private unit
+(def ^:private unit-tuple
(&/T [(&/T ["" -1 -1]) (&/$TupleS &/$Nil)]))
(defn ^:private resolve-type [type]
@@ -237,11 +237,20 @@
idx (&module/tag-index =module =name)
group (&module/tag-group =module =name)
case-type (&type/sum-at idx value-type*)
- [=test =kont] (analyse-pattern &/$None case-type unit kont)]
+ [=test =kont] (analyse-pattern &/$None case-type unit-tuple kont)]
(return (&/T [($VariantTestAC (&/T [idx (&/|length group) =test])) =kont])))
- (&/$FormS (&/$Cons [_ (&/$TagS ?ident)]
- ?values))
+ (&/$FormS (&/$Cons [_ (&/$IntS idx)] ?values))
+ (|do [value-type* (adjust-type value-type)
+ case-type (&type/sum-at idx value-type*)
+ [=test =kont] (case (int (&/|length ?values))
+ 0 (analyse-pattern &/$None case-type unit-tuple kont)
+ 1 (analyse-pattern &/$None case-type (&/|head ?values) kont)
+ ;; 1+
+ (analyse-pattern &/$None case-type (&/T [(&/T ["" -1 -1]) (&/$TupleS ?values)]) kont))]
+ (return (&/T [($VariantTestAC (&/T [idx (&/|length (&type/flatten-sum value-type*)) =test])) =kont])))
+
+ (&/$FormS (&/$Cons [_ (&/$TagS ?ident)] ?values))
(|do [[=module =name] (&&/resolved-ident ?ident)
must-infer? (&type/unknown? value-type)
variant-type (if must-infer?
@@ -255,7 +264,7 @@
group (&module/tag-group =module =name)
case-type (&type/sum-at idx value-type*)
[=test =kont] (case (int (&/|length ?values))
- 0 (analyse-pattern &/$None case-type unit kont)
+ 0 (analyse-pattern &/$None case-type unit-tuple kont)
1 (analyse-pattern &/$None case-type (&/|head ?values) kont)
;; 1+
(analyse-pattern &/$None case-type (&/T [(&/T ["" -1 -1]) (&/$TupleS ?values)]) kont))]
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index 8492d5766..a0891371b 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -472,7 +472,7 @@
_ (&type/delete-var _inf-var)]
(return _func*)))
=func
- (&/|reverse (&type/unfold-prod =input)))
+ (&/|reverse (&type/flatten-prod =input)))
_
(|do [=func* (&type/clean $input =func)
diff --git a/src/lux/type.clj b/src/lux/type.clj
index 614d51eb3..70a2f69fa 100644
--- a/src/lux/type.clj
+++ b/src/lux/type.clj
@@ -902,20 +902,6 @@
fold-sum &/$VoidT &/$SumT
)
-
-(do-template [<name> <ctor>]
- (defn <name> [type]
- (|case type
- (<ctor> l r)
- (&/$Cons l (<name> r))
-
- _
- (&/|list type)))
-
- unfold-prod &/$ProdT
- unfold-sum &/$SumT
- )
-
(def create-var+
(|do [id create-var]
(return (&/$VarT id))))