Commit f5aeb375 authored by Robert Bradshaw's avatar Robert Bradshaw

error on local cimport (rather than traceback)

parent 0d467db3
...@@ -3296,6 +3296,9 @@ class CImportStatNode(StatNode): ...@@ -3296,6 +3296,9 @@ class CImportStatNode(StatNode):
# as_name string or None Name specified in "as" clause, if any # as_name string or None Name specified in "as" clause, if any
def analyse_declarations(self, env): def analyse_declarations(self, env):
if not env.is_module_scope:
error(self.pos, "cimport only allowed at module level")
return
module_scope = env.find_module(self.module_name, self.pos) module_scope = env.find_module(self.module_name, self.pos)
if "." in self.module_name: if "." in self.module_name:
names = self.module_name.split(".") names = self.module_name.split(".")
...@@ -3328,6 +3331,9 @@ class FromCImportStatNode(StatNode): ...@@ -3328,6 +3331,9 @@ class FromCImportStatNode(StatNode):
# imported_names [(pos, name, as_name)] Names to be imported # imported_names [(pos, name, as_name)] Names to be imported
def analyse_declarations(self, env): def analyse_declarations(self, env):
if not env.is_module_scope:
error(self.pos, "cimport only allowed at module level")
return
module_scope = env.find_module(self.module_name, self.pos) module_scope = env.find_module(self.module_name, self.pos)
env.add_imported_module(module_scope) env.add_imported_module(module_scope)
for pos, name, as_name in self.imported_names: for pos, name, as_name in self.imported_names:
......
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