From ab6e3d1b3ef09608af97a36a3e8f5869e69b63eb Mon Sep 17 00:00:00 2001
From: Adam Sampson <ats@offog.org>
Date: Sun, 6 Apr 2008 17:59:29 +0000
Subject: [PATCH] Infer the types of channel arrays.

---
 frontends/OccamTypes.hs | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/frontends/OccamTypes.hs b/frontends/OccamTypes.hs
index 6e47aec..10b80e3 100644
--- a/frontends/OccamTypes.hs
+++ b/frontends/OccamTypes.hs
@@ -725,6 +725,20 @@ inferTypes = applyExplicitM9 doExpression doDimension doSubscript
                            A.Infer -> typeOfExpression e'
                            _ -> return t'
                   return $ A.IsExpr m am' t'' e'
+            A.IsChannelArray m t vs ->
+               -- No expressions in this -- but we may need to infer the type
+               -- of the variable if it's something like "cs IS [c]:".
+               do t' <- inferTypes t
+                  vs' <- mapM inferTypes vs
+                  let dim = makeDimension m $ length vs'
+                  t'' <- case (t', vs') of
+                           (A.Infer, (v:_)) ->
+                             do elemT <- typeOfVariable v
+                                return $ addDimensions [dim] elemT
+                           (A.Infer, []) ->
+                             dieP m "Cannot infer type of empty channel array"
+                           _ -> return $ applyDimension dim t'
+                  return $ A.IsChannelArray m t'' vs'
             A.Function m sm ts fs (Left sel) ->
                do sm' <- inferTypes sm
                   ts' <- inferTypes ts