Commit 099b2b90 authored by Rudi Chen's avatar Rudi Chen

Loosen type annotation to allow NotImplemented.

parent 06339b3b
......@@ -4157,6 +4157,11 @@ Box* callCLFunc(FunctionMetadata* md, CallRewriteArgs* rewrite_args, int num_out
if (!r) {
assert(S == CAPI);
} else {
// If this assertion is triggered because the type isn't what we expected,
// but something that should be allowed (e.g. NotImplementedType), it is
// possible that the program has a bad type annotation. For example, an
// attribute that we added in C++ should have return type UNKNOWN instead
// of BOXED_SOMETHING.
ASSERT(chosen_cf->spec->rtn_type->isFitBy(r->cls), "%s (%p) was supposed to return %s, but gave a %s",
g.func_addr_registry.getFuncNameAtAddress(chosen_cf->code, true, NULL).c_str(), chosen_cf->code,
chosen_cf->spec->rtn_type->debugName().c_str(), r->cls->tp_name);
......
......@@ -687,7 +687,9 @@ void setupTuple() {
tuple_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)tupleLen, BOXED_INT, 1)));
tuple_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)tupleRepr, STR, 1)));
tuple_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)tupleAdd, BOXED_TUPLE, 2)));
// Return type is UNKNOWN as it could be NotImplemented.
tuple_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)tupleAdd, UNKNOWN, 2)));
tuple_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, BOXED_TUPLE, 2)));
tuple_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, BOXED_TUPLE, 2)));
......
......@@ -95,6 +95,11 @@ print (1, 2, 3) + ()
print () + (1, 2, 3)
print (1, 2) + (2, 3)
try:
(1, 2) + "a"
except TypeError as e:
print "adding failed"
## __new__
print tuple()
print tuple((1,3,7,42))
......
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