Commit 1a0c1320 authored by Stefan Behnel's avatar Stefan Behnel

Prevent unknown names in annotations from being interpreted (and declared!) as builtins.

Closes #1887.
parent 70fc8bb1
...@@ -1362,18 +1362,17 @@ def _analyse_name_as_type(name, pos, env): ...@@ -1362,18 +1362,17 @@ def _analyse_name_as_type(name, pos, env):
type = PyrexTypes.parse_basic_type(name) type = PyrexTypes.parse_basic_type(name)
if type is not None: if type is not None:
return type return type
with local_errors(ignore=True):
from .TreeFragment import TreeFragment from .TreeFragment import TreeFragment
with local_errors(ignore=True):
pos = (pos[0], pos[1], pos[2]-7) pos = (pos[0], pos[1], pos[2]-7)
try: try:
declaration = TreeFragment(u"sizeof(%s)" % name, name=pos[0].filename, initial_pos=pos) declaration = TreeFragment(u"sizeof(%s)" % name, name=pos[0].filename, initial_pos=pos)
except CompileError: except CompileError:
sizeof_node = None pass
else: else:
sizeof_node = declaration.root.stats[0].expr sizeof_node = declaration.root.stats[0].expr
sizeof_node = sizeof_node.analyse_types(env)
if isinstance(sizeof_node, SizeofTypeNode): if isinstance(sizeof_node, SizeofTypeNode):
return sizeof_node.arg_type return sizeof_node.arg_type.analyse_types(env)
return None return None
......
...@@ -196,6 +196,25 @@ def call_exception_default(raise_exc=False): ...@@ -196,6 +196,25 @@ def call_exception_default(raise_exc=False):
return exception_default(raise_exc) return exception_default(raise_exc)
class EarlyClass(object):
"""
>>> a = EarlyClass(1)
>>> a.string_forward_declaration() # should probably raise an error at some point
1
>>> x = LateClass()
>>> a = EarlyClass(x)
>>> x2 = a.string_forward_declaration()
>>> assert x is x2, x2
"""
def __init__(self, x):
self.x = x
def string_forward_declaration(self) -> 'LateClass':
return self.x
class LateClass(object):
pass
_WARNINGS = """ _WARNINGS = """
8:32: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly. 8:32: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly.
8:47: Dicts should no longer be used as type annotations. Use 'cython.int' etc. directly. 8:47: Dicts should no longer be used as type annotations. Use 'cython.int' etc. directly.
...@@ -203,6 +222,7 @@ _WARNINGS = """ ...@@ -203,6 +222,7 @@ _WARNINGS = """
8:77: Dicts should no longer be used as type annotations. Use 'cython.int' etc. directly. 8:77: Dicts should no longer be used as type annotations. Use 'cython.int' etc. directly.
8:85: Python type declaration in signature annotation does not refer to a Python type 8:85: Python type declaration in signature annotation does not refer to a Python type
8:85: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly. 8:85: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly.
211:44: Unknown type declaration in annotation, ignoring
# BUG: # BUG:
46:6: 'pytypes_cpdef' redeclared 46:6: 'pytypes_cpdef' redeclared
121:0: 'struct_io' redeclared 121:0: 'struct_io' redeclared
......
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