diff --git a/common/Types.hs b/common/Types.hs index 040e9f9..d34b850 100644 --- a/common/Types.hs +++ b/common/Types.hs @@ -215,19 +215,19 @@ subscriptType sub t = diePC (findMeta sub) $ formatCode "Unsubscriptable type: % -- | The inverse of 'subscriptType': given a type that we know is the result of -- a subscript, return what the type being subscripted is. -unsubscriptType :: (CSMR m, Die m) => A.Subscript -> A.Type -> m A.Type +unsubscriptType :: A.Subscript -> A.Type -> Maybe A.Type unsubscriptType _ A.Infer - = return $ A.Infer + = Just $ A.Infer unsubscriptType (A.SubscriptFromFor _ _ _ _) t - = return $ removeFixedDimension t + = Just $ removeFixedDimension t unsubscriptType (A.SubscriptFrom _ _ _) t - = return $ removeFixedDimension t + = Just $ removeFixedDimension t unsubscriptType (A.SubscriptFor _ _ _) t - = return $ removeFixedDimension t + = Just $ removeFixedDimension t unsubscriptType (A.SubscriptField m _) t - = dieP m $ "unsubscript of record type (but we can't tell which one)" + = Nothing unsubscriptType (A.Subscript _ _ sub) t - = return $ addDimensions [A.UnknownDimension] t + = Just $ addDimensions [A.UnknownDimension] t -- | Just remove the first dimension from an array type -- like doing -- subscriptType with constant 0 as a subscript, but without the checking. diff --git a/frontends/OccamTypes.hs b/frontends/OccamTypes.hs index 9425e16..bc689d3 100644 --- a/frontends/OccamTypes.hs +++ b/frontends/OccamTypes.hs @@ -686,10 +686,7 @@ inferTypes = occamOnlyPass "Infer types" A.IntrinsicFunctionCall _ _ _ -> noTypeContext $ descend outer A.SubscriptedExpr m s e -> do ctx <- getTypeContext - ctx' <- case ctx of - Just t -> unsubscriptType s t >>* Just - Nothing -> return Nothing - e' <- inTypeContext ctx' $ recurse e + e' <- inTypeContext (ctx >>= unsubscriptType s) $ recurse e t <- astTypeOf e' s' <- recurse s >>= fixSubscript t return $ A.SubscriptedExpr m s' e'