Fixed type-checking on ambigious record fields, so that now the cgtests are happy again

This commit is contained in:
Neil Brown 2009-04-08 19:11:33 +00:00
parent 82be1bd726
commit de097bb138
2 changed files with 8 additions and 11 deletions

View File

@ -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.

View File

@ -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'