@@ -1379,8 +1379,14 @@ typeForGraphRefRelationalExpr NotEquals{} = do
1379typeForGraphRefRelationalExpr (Extend extendTupleExpr expr) = do
1379typeForGraphRefRelationalExpr (Extend extendTupleExpr expr) = do
1380 rel <- typeForGraphRefRelationalExpr expr
1380 rel <- typeForGraphRefRelationalExpr expr
1381 evalGraphRefRelationalExpr (Extend extendTupleExpr (ExistingRelation rel))
1381 evalGraphRefRelationalExpr (Extend extendTupleExpr (ExistingRelation rel))
1382−typeForGraphRefRelationalExpr expr@With{} = do
1382+typeForGraphRefRelationalExpr expr@(With withs _) = do
1383 let expr' = substituteWithNameMacros [] expr
1383 let expr' = substituteWithNameMacros [] expr
1384+ checkMacroName (WithNameExpr macroName tid) = do
1385+ rvs <- relationVariables <$> gfDatabaseContextForMarker tid
1386+ case M.lookup macroName rvs of
1387+ Just _ -> lift $ except $ Left (RelVarAlreadyDefinedError macroName) --this error does not include the transaction marker, but should be good enough to identify the cause
1389+ mapM checkMacroName (map fst withs)
1384 typeForGraphRefRelationalExpr expr'
1390 typeForGraphRefRelationalExpr expr'
1386evalGraphRefAttributeNames :: GraphRefAttributeNames -> GraphRefRelationalExpr -> GraphRefRelationalExprM (S.Set AttributeName)
1392evalGraphRefAttributeNames :: GraphRefAttributeNames -> GraphRefRelationalExpr -> GraphRefRelationalExprM (S.Set AttributeName)