fixed variables

This commit is contained in:
pca006132 2020-12-18 13:09:15 +08:00 committed by pca006132
parent ce031999e9
commit 60c1e99285
2 changed files with 7 additions and 4 deletions

View File

@ -119,15 +119,15 @@ def resolve_call(obj,
if len(obj.constraints) == 0: if len(obj.constraints) == 0:
raise CustomError("no methods for unconstrained object") raise CustomError("no methods for unconstrained object")
results = [resolve_call(obj, fn, args, assumptions | {obj.name: v}, ctx) results = [resolve_call(obj, fn, args, assumptions | {obj.name: v}, ctx)
for v in obj.assumptions] for v in obj.constraints]
for v in results[1:]: for v in results[1:]:
if v != results[0]: if v != results[0]:
break break
else: else:
# same result # same result
return results[0] return results[0]
results = [v.inv_subst([a, obj]) results = [v.inv_subst([(a, obj)])
for v, a in zip(results, obj.assumptions)] for v, a in zip(results, obj.constraints)]
for v in results[1:]: for v in results[1:]:
if v != results[0]: if v != results[0]:
break break

View File

@ -28,14 +28,15 @@ A = variables['A']
i32.methods['__init__'] = ([SelfType(), I], None, set()) i32.methods['__init__'] = ([SelfType(), I], None, set())
i32.methods['__add__'] = ([SelfType(), i32], i32, set()) i32.methods['__add__'] = ([SelfType(), i32], i32, set())
i32.methods['__sub__'] = ([SelfType(), i32], i32, set()) i32.methods['__sub__'] = ([SelfType(), i32], i32, set())
i32.methods['foo'] = ([SelfType(), i32], i32, set())
i64.methods['__init__'] = ([SelfType(), I], None, set()) i64.methods['__init__'] = ([SelfType(), I], None, set())
i64.methods['__add__'] = ([SelfType(), i64], i64, set()) i64.methods['__add__'] = ([SelfType(), i64], i64, set())
i64.methods['__sub__'] = ([SelfType(), i64], i64, set()) i64.methods['__sub__'] = ([SelfType(), i64], i64, set())
i64.methods['foo'] = ([SelfType(), i64], i32, set())
ctx = Context(variables, types) ctx = Context(variables, types)
def test_call(obj, fn, args, assumptions = {}): def test_call(obj, fn, args, assumptions = {}):
args_str = ', '.join([str(v) for v in args]) args_str = ', '.join([str(v) for v in args])
obj_str = '' if obj is None else str(obj) + '.' obj_str = '' if obj is None else str(obj) + '.'
@ -56,5 +57,7 @@ test_call(i32, '__add__', [])
test_call(i32, '__add__', [i32]) test_call(i32, '__add__', [i32])
test_call(i32, '__add__', [i64]) test_call(i32, '__add__', [i64])
test_call(i32, '__add__', [i32, i32]) test_call(i32, '__add__', [i32, i32])
test_call(I, '__add__', [I])
test_call(I, 'foo', [I])