Commit 78871be7 authored by Robert Bradshaw's avatar Robert Bradshaw

C++ class constructor calls.

parent b6df7f92
......@@ -2453,6 +2453,15 @@ class CallNode(ExprNode):
self.analyse_types(env)
self.coerce_to(type, env)
return True
elif type and type.is_cpp_class:
for arg in self.args:
arg.analyse_types(env)
constructor = type.scope.lookup("<init>")
self.function = RawCNameExprNode(self.function.pos, constructor.type)
self.function.entry = constructor
self.function.set_cname(type.declaration_code(""))
self.analyse_c_function_call(env)
return True
def nogil_check(self, env):
func_type = self.function_type()
......
......@@ -1890,6 +1890,8 @@ class CppClassType(CType):
def assignable_from_resolved_type(self, other_type):
# TODO: handle operator=(...) here?
if other_type is error_type:
return True
return other_type.is_cpp_class and other_type.is_subclass(self)
def attributes_known(self):
......
......@@ -1536,6 +1536,7 @@ class CppClassScope(Scope):
api = 0, in_pxd = 0, modifiers = ()):
if name == self.name.split('::')[-1] and cname is None:
name = '<init>'
type.return_type = self.lookup(self.name).type
prev_entry = self.lookup_here(name)
entry = self.declare_var(name, type, pos, cname, visibility)
if prev_entry:
......
......@@ -22,8 +22,7 @@ def test_wrap_pair(int i, double x):
(2, 2.25, True)
"""
try:
pair = new Pair[int, double](i, x)
wrap = new Wrap[Pair[int, double]](deref(pair))
wrap = new Wrap[Pair[int, double]](Pair[int, double](i, x))
return wrap.get().first(), wrap.get().second(), deref(wrap) == deref(wrap)
finally:
del pair, wrap
del wrap
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