Commit de4aa5fe authored by Stefan Behnel's avatar Stefan Behnel

Always show original position on "redeclared" errors.

parent da1a7d09
...@@ -218,9 +218,12 @@ class Entry(object): ...@@ -218,9 +218,12 @@ class Entry(object):
def __repr__(self): def __repr__(self):
return "%s(<%x>, name=%s, type=%s)" % (type(self).__name__, id(self), self.name, self.type) return "%s(<%x>, name=%s, type=%s)" % (type(self).__name__, id(self), self.name, self.type)
def already_declared_here(self):
error(self.pos, "Previous declaration is here")
def redeclared(self, pos): def redeclared(self, pos):
error(pos, "'%s' does not match previous declaration" % self.name) error(pos, "'%s' does not match previous declaration" % self.name)
error(self.pos, "Previous declaration is here") self.already_declared_here()
def all_alternatives(self): def all_alternatives(self):
return [self] + self.overloaded_alternatives return [self] + self.overloaded_alternatives
...@@ -456,6 +459,7 @@ class Scope(object): ...@@ -456,6 +459,7 @@ class Scope(object):
warning(pos, "'%s' redeclared " % name, 1 if self.in_cinclude else 0) warning(pos, "'%s' redeclared " % name, 1 if self.in_cinclude else 0)
elif visibility != 'ignore': elif visibility != 'ignore':
error(pos, "'%s' redeclared " % name) error(pos, "'%s' redeclared " % name)
entries[name].already_declared_here()
entry = Entry(name, cname, type, pos = pos) entry = Entry(name, cname, type, pos = pos)
entry.in_cinclude = self.in_cinclude entry.in_cinclude = self.in_cinclude
entry.create_wrapper = create_wrapper entry.create_wrapper = create_wrapper
...@@ -587,6 +591,7 @@ class Scope(object): ...@@ -587,6 +591,7 @@ class Scope(object):
else: else:
if not (entry.is_type and entry.type.is_cpp_class): if not (entry.is_type and entry.type.is_cpp_class):
error(pos, "'%s' redeclared " % name) error(pos, "'%s' redeclared " % name)
entry.already_declared_here()
return None return None
elif scope and entry.type.scope: elif scope and entry.type.scope:
warning(pos, "'%s' already defined (ignoring second definition)" % name, 0) warning(pos, "'%s' already defined (ignoring second definition)" % name, 0)
...@@ -597,11 +602,13 @@ class Scope(object): ...@@ -597,11 +602,13 @@ class Scope(object):
if base_classes: if base_classes:
if entry.type.base_classes and entry.type.base_classes != base_classes: if entry.type.base_classes and entry.type.base_classes != base_classes:
error(pos, "Base type does not match previous declaration") error(pos, "Base type does not match previous declaration")
entry.already_declared_here()
else: else:
entry.type.base_classes = base_classes entry.type.base_classes = base_classes
if templates or entry.type.templates: if templates or entry.type.templates:
if templates != entry.type.templates: if templates != entry.type.templates:
error(pos, "Template parameters do not match previous declaration") error(pos, "Template parameters do not match previous declaration")
entry.already_declared_here()
def declare_inherited_attributes(entry, base_classes): def declare_inherited_attributes(entry, base_classes):
for base_class in base_classes: for base_class in base_classes:
...@@ -1733,6 +1740,7 @@ class LocalScope(Scope): ...@@ -1733,6 +1740,7 @@ class LocalScope(Scope):
orig_entry = self.lookup_here(name) orig_entry = self.lookup_here(name)
if orig_entry and orig_entry.scope is self and not orig_entry.from_closure: if orig_entry and orig_entry.scope is self and not orig_entry.from_closure:
error(pos, "'%s' redeclared as nonlocal" % name) error(pos, "'%s' redeclared as nonlocal" % name)
orig_entry.already_declared_here()
else: else:
entry = self.lookup(name) entry = self.lookup(name)
if entry is None or not entry.from_closure: if entry is None or not entry.from_closure:
...@@ -1966,6 +1974,7 @@ class PyClassScope(ClassScope): ...@@ -1966,6 +1974,7 @@ class PyClassScope(ClassScope):
orig_entry = self.lookup_here(name) orig_entry = self.lookup_here(name)
if orig_entry and orig_entry.scope is self and not orig_entry.from_closure: if orig_entry and orig_entry.scope is self and not orig_entry.from_closure:
error(pos, "'%s' redeclared as nonlocal" % name) error(pos, "'%s' redeclared as nonlocal" % name)
orig_entry.already_declared_here()
else: else:
entry = self.lookup(name) entry = self.lookup(name)
if entry is None: if entry is None:
......
...@@ -30,7 +30,9 @@ def redef_in_class_scope(): ...@@ -30,7 +30,9 @@ def redef_in_class_scope():
_ERRORS = u""" _ERRORS = u"""
4:4: no binding for nonlocal 'no_such_name' found 4:4: no binding for nonlocal 'no_such_name' found
10:8: Previous declaration is here
11:8: 'x' redeclared as nonlocal 11:8: 'x' redeclared as nonlocal
16:4: no binding for nonlocal 'global_name' found 16:4: no binding for nonlocal 'global_name' found
27:8: Previous declaration is here
28:8: 'x' redeclared as nonlocal 28:8: 'x' redeclared as nonlocal
""" """
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment