From 07ec6752ee2bc8b51b1c3212ed351bb8c50962ff Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Tue, 27 Nov 2018 17:09:38 +0000 Subject: [PATCH] Introduce yet another new error. --- src/sixtypical/analyzer.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index ad0c636..edd067c 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -34,6 +34,11 @@ class InconsistentInitializationError(StaticAnalysisError): pass +class InconsistentExitError(StaticAnalysisError): + """The type context differs at two different exit points of the routine.""" + pass + + class ForbiddenWriteError(StaticAnalysisError): pass @@ -156,6 +161,10 @@ class Context(object): for ref in self._touched: yield ref + def each_writeable(self): + for ref in self._writeable: + yield ref + def assert_meaningful(self, *refs, **kwargs): exception_class = kwargs.get('exception_class', UnmeaningfulReadError) for ref in refs: @@ -419,12 +428,14 @@ class Analyzer(object): exit_context = self.exit_contexts[0] exit_meaningful = set(exit_context.each_meaningful()) exit_touched = set(exit_context.each_touched()) + exit_writeable = set(exit_context.each_writeable()) for ex in self.exit_contexts[1:]: if set(ex.each_meaningful()) != exit_meaningful: - raise InconsistentInitializationError('?') + raise InconsistentExitError("Exit contexts are not consistent") if set(ex.each_touched()) != exit_touched: - raise InconsistentInitializationError('?') - # FIXME: confirm writeable sets are the same too? + raise InconsistentExitError("Exit contexts are not consistent") + if set(ex.each_writeable()) != exit_writeable: + raise InconsistentExitError("Exit contexts are not consistent") context.update_from(exit_context) trashed = set(context.each_touched()) - set(context.each_meaningful())