From 543a06944075c3829bf4eb34e1ff181177db045e Mon Sep 17 00:00:00 2001 From: Renata Hodovan Date: Tue, 9 Aug 2016 22:41:59 +0200 Subject: [PATCH] Fix comparisons in ATNConfigSet.__contains__ of Python targets. The __contains__ method of ATNConfigSet used different hashing function (hash) for indexing the config dictionary than the getOrAdd method (hashCodeForConfigSet) which filled it. Furthermore, they also used different methods for comparing ATNConfig objects. The patch makes them consistent. --- runtime/Python2/src/antlr4/atn/ATNConfigSet.py | 8 ++++++-- runtime/Python3/src/antlr4/atn/ATNConfigSet.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/Python2/src/antlr4/atn/ATNConfigSet.py b/runtime/Python2/src/antlr4/atn/ATNConfigSet.py index d5a73eb38..d5748159c 100755 --- a/runtime/Python2/src/antlr4/atn/ATNConfigSet.py +++ b/runtime/Python2/src/antlr4/atn/ATNConfigSet.py @@ -195,9 +195,13 @@ class ATNConfigSet(object): def __contains__(self, config): if self.configLookup is None: raise UnsupportedOperationException("This method is not implemented for readonly sets.") - h = hash(config) + h = config.hashCodeForConfigSet() l = self.configLookup.get(h, None) - return l is not None and config in l + if l is not None: + for c in l: + if config.equalsForConfigSet(c): + return True + return False def clear(self): if self.readonly: diff --git a/runtime/Python3/src/antlr4/atn/ATNConfigSet.py b/runtime/Python3/src/antlr4/atn/ATNConfigSet.py index e499ac947..13d476558 100755 --- a/runtime/Python3/src/antlr4/atn/ATNConfigSet.py +++ b/runtime/Python3/src/antlr4/atn/ATNConfigSet.py @@ -198,9 +198,13 @@ class ATNConfigSet(object): def __contains__(self, config): if self.configLookup is None: raise UnsupportedOperationException("This method is not implemented for readonly sets.") - h = hash(config) + h = config.hashCodeForConfigSet() l = self.configLookup.get(h, None) - return l is not None and config in l + if l is not None: + for c in l: + if config.equalsForConfigSet(c): + return True + return False def clear(self): if self.readonly: