From 60c1e992852334d1f87f6f4b060783e3599b170c Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 18 Dec 2020 13:09:15 +0800 Subject: [PATCH] fixed variables --- toy-impl/inference.py | 6 +++--- toy-impl/test_inference.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/toy-impl/inference.py b/toy-impl/inference.py index 976564d..c2aa954 100644 --- a/toy-impl/inference.py +++ b/toy-impl/inference.py @@ -119,15 +119,15 @@ def resolve_call(obj, if len(obj.constraints) == 0: raise CustomError("no methods for unconstrained object") 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:]: if v != results[0]: break else: # same result return results[0] - results = [v.inv_subst([a, obj]) - for v, a in zip(results, obj.assumptions)] + results = [v.inv_subst([(a, obj)]) + for v, a in zip(results, obj.constraints)] for v in results[1:]: if v != results[0]: break diff --git a/toy-impl/test_inference.py b/toy-impl/test_inference.py index e18ccb7..713537c 100644 --- a/toy-impl/test_inference.py +++ b/toy-impl/test_inference.py @@ -28,14 +28,15 @@ A = variables['A'] i32.methods['__init__'] = ([SelfType(), I], None, set()) i32.methods['__add__'] = ([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['__add__'] = ([SelfType(), i64], i64, set()) i64.methods['__sub__'] = ([SelfType(), i64], i64, set()) +i64.methods['foo'] = ([SelfType(), i64], i32, set()) ctx = Context(variables, types) - def test_call(obj, fn, args, assumptions = {}): args_str = ', '.join([str(v) for v in args]) 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__', [i64]) test_call(i32, '__add__', [i32, i32]) +test_call(I, '__add__', [I]) +test_call(I, 'foo', [I])