Commit c35599ce authored by Robert Bradshaw's avatar Robert Bradshaw

Fix lots of tests errors, all tests pass.

parent f77650eb
......@@ -2429,14 +2429,6 @@ class SimpleCallNode(CallNode):
self.function.entry = entry
self.function.type = entry.type
func_type = self.function_type()
# Check function type
if not func_type.is_cfunction:
if not func_type.is_error:
error(self.pos, "Calling non-function type '%s'" %
func_type)
self.type = PyrexTypes.error_type
self.result_code = "<error>"
return
# Check no. of args
max_nargs = len(func_type.args)
expected_nargs = max_nargs - func_type.optional_arg_count
......@@ -2479,7 +2471,7 @@ class SimpleCallNode(CallNode):
def c_call_code(self):
func_type = self.function_type()
if self.args is None or not func_type.is_cfunction:
if self.type is PyrexTypes.error_type or not func_type.is_cfunction:
return "<error>"
formal_args = func_type.args
arg_list_code = []
......@@ -3772,8 +3764,8 @@ class UnopNode(ExprNode):
self.type = py_object_type
self.gil_check(env)
self.is_temp = 1
elif self.is_cpp_operation:
self.analyse_cpp_operation
elif self.is_cpp_operation():
self.analyse_cpp_operation(env)
else:
self.analyse_c_operation(env)
......
......@@ -775,9 +775,6 @@ class TemplatedTypeNode(CBaseTypeNode):
else:
if not isinstance(env, Symtab.LocalScope):
error(self.pos, ERR_BUF_LOCALONLY)
import Buffer
options = Buffer.analyse_buffer_options(
......@@ -5817,4 +5814,3 @@ proto="""
#------------------------------------------------------------------------------------
ERR_BUF_LOCALONLY = 'Buffer types only allowed as function local variables'
......@@ -1458,6 +1458,8 @@ class CppClassType(CType):
if self == other_type:
return 1
elif self.template_type == other_type.template_type:
if self.templates == other_type.templates:
return 1
for t1, t2 in zip(self.templates, other_type.templates):
if not t1.same_as_resolved_type(t2):
return 0
......@@ -1770,14 +1772,27 @@ def best_match(args, functions, pos):
func_type = func.type
if func_type.is_ptr:
func_type = func_type.base_type
# Check function type
if not func_type.is_cfunction:
if not func_type.is_error:
error(pos, "Calling non-function type '%s'" % func_type)
return None
# Check no. of args
max_nargs = len(func_type.args)
min_nargs = max_nargs - func_type.optional_arg_count
if actual_nargs < min_nargs \
or (not func_type.has_varargs and actual_nargs > max_nargs):
if max_nargs == min_nargs and not func_type.has_varargs:
expectation = max_nargs
elif actual_nargs < min_nargs:
expectation = "at least %s" % min_nargs
else:
expectation = "at most %s" % max_nargs
error_str = "Call with wrong number of arguments (expected %s, got %s)" \
% (expectation, actual_nargs)
continue
score = [0,0,0]
for i in range(len(args)):
for i in range(min(len(args), len(func_type.args))):
src_type = args[i].type
dst_type = func_type.args[i].type
if dst_type.assignable_from(src_type):
......@@ -1804,8 +1819,7 @@ def best_match(args, functions, pos):
# This will raise the right error.
return func
else:
error(pos, "Call with wrong number of arguments (expected %s, got %s)"
% (expected_str, actual_nargs))
error(pos, error_str)
return None
......
......@@ -301,25 +301,21 @@ class Scope(object):
# Create new entry, and add to dictionary if
# name is not None. Reports a warning if already
# declared.
if type.is_buffer and not isinstance(self, LocalScope):
error(pos, ERR_BUF_LOCALONLY)
if not self.in_cinclude and cname and re.match("^_[_A-Z]+$", cname):
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
warning(pos, "'%s' is a reserved name in C." % cname, -1)
entries = self.entries
overloaded = False
if name and name in entries:
if visibility == 'extern':
warning(pos, "'%s' redeclared " % name, 0)
elif visibility != 'ignore':
overloaded = True
#error(pos, "'%s' redeclared " % name)
error(pos, "'%s' redeclared " % name)
entry = Entry(name, cname, type, pos = pos)
entry.in_cinclude = self.in_cinclude
if name:
entry.qualified_name = self.qualify_name(name)
if overloaded:
entries[name].overloaded_alternatives.append(entry)
#print entries[name].overloaded_alternatives
else:
entries[name] = entry
entry.scope = self
entry.visibility = visibility
......@@ -464,13 +460,14 @@ class Scope(object):
cname = self.mangle(Naming.func_prefix, name)
entry = self.lookup_here(name)
if entry:
entry.overloaded_alternatives.append(self.add_cfunction(name, type, pos, cname, visibility, modifiers))
if visibility != 'private' and visibility != entry.visibility:
warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1)
if not entry.type.same_as(type):
if visibility == 'extern' and entry.visibility == 'extern':
warning(pos, "Function signature does not match previous declaration", 1)
#entry.type = type
entry.overloaded_alternatives.append(
self.add_cfunction(name, type, pos, cname, visibility, modifiers))
else:
error(pos, "Function signature does not match previous declaration")
else:
......@@ -1113,6 +1110,10 @@ class ModuleScope(Scope):
#
return entry
def check_for_illegal_incomplete_ctypedef(self, typedef_flag, pos):
if typedef_flag and not self.in_cinclude:
error(pos, "Forward-referenced type must use 'cdef', not 'ctypedef'")
def declare_cpp_class(self, name, scope,
pos, cname = None, base_classes = [],
visibility = 'extern', templates = None):
......@@ -1626,6 +1627,11 @@ class CppClassScope(Scope):
"C++ class member cannot be a Python object")
return entry
def declare_cfunction(self, name, type, pos,
cname = None, visibility = 'extern', defining = 0,
api = 0, in_pxd = 0, modifiers = ()):
entry = self.declare_var(name, type, pos, cname, visibility)
def declare_inherited_cpp_attributes(self, base_scope):
# Declare entries for all the C++ attributes of an
# inherited type, with cnames modified appropriately
......@@ -1638,7 +1644,7 @@ class CppClassScope(Scope):
self.inherited_var_entries.append(entry)
for base_entry in base_scope.cfunc_entries:
entry = self.declare_cfunction(base_entry.name, base_entry.type,
base_entry.pos, adapt(base_entry.cname),
base_entry.pos, base_entry.cname,
base_entry.visibility, base_entry.func_modifiers)
entry.is_inherited = 1
......@@ -1699,3 +1705,7 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
return NULL;
}
""")
#------------------------------------------------------------------------------------
ERR_BUF_LOCALONLY = 'Buffer types only allowed as function local variables'
......@@ -12,8 +12,8 @@ def f():
cdef object[int, 2, well] buf6
_ERRORS = u"""
1:11: Buffer types only allowed as function local variables
3:15: Buffer types only allowed as function local variables
1:17: Buffer types only allowed as function local variables
3:21: Buffer types only allowed as function local variables
6:27: "fakeoption" is not a buffer option
"""
#TODO:
......
......@@ -13,8 +13,8 @@ def f(a):
del s.m # error: deletion of non-Python object
_ERRORS = u"""
8:6: Cannot assign to or delete this
9:45: Deletion of non-Python object
12:6: Deletion of non-Python object
13:6: Deletion of non-Python object
9:45: Deletion of non-Python, non-C++ object
12:6: Deletion of non-Python, non-C++ object
13:6: Deletion of non-Python, non-C++ object
11:52: Deletion of local or C global name not supported
"""
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