# HG changeset patch # User Paul Boddie # Date 1529680409 -7200 # Node ID 8e9566713e1a2ee942a8a5261781799ede5a91cb # Parent d329acb71a6aca5023b85ebfd9cc5f4d58b3314a Fixed accessor tests to raise type errors instead of returning zero. diff -r d329acb71a6a -r 8e9566713e1a deducer.py --- a/deducer.py Fri Jun 22 15:18:04 2018 +0200 +++ b/deducer.py Fri Jun 22 17:13:29 2018 +0200 @@ -3,7 +3,7 @@ """ Deduce types for usage observations. -Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie +Copyright (C) 2014, 2015, 2016, 2017, 2018 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -2713,11 +2713,15 @@ accessor = (stored_accessor,) else: accessor = (original_accessor,) + else: + accessor = None # Apply any test. if test[0] == "test": - accessor = ("__%s_%s_%s" % test, accessor, test_type) + test_accessor = accessor = ("__to_error", ("__%s_%s_%s" % test, accessor, test_type)) + else: + test_accessor = None # Perform the first or final access. # The access only needs performing if the resulting accessor is used. diff -r d329acb71a6a -r 8e9566713e1a templates/ops.h --- a/templates/ops.h Fri Jun 22 15:18:04 2018 +0200 +++ b/templates/ops.h Fri Jun 22 17:13:29 2018 +0200 @@ -1,6 +1,6 @@ /* Common operations. -Copyright (C) 2015, 2016, 2017 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -71,6 +71,8 @@ __ref __test_common_object__(__ref obj, int pos, int code); __ref __test_common_type__(__ref obj, int pos, int code); +#define __to_error(REF) (REF ? REF : (__raise_type_error(), (__ref) 0)) + #define __test_common_instance(OBJ, TYPENAME) (__test_common_instance__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) #define __test_common_object(OBJ, TYPENAME) (__test_common_object__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) #define __test_common_type(OBJ, TYPENAME) (__test_common_type__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME)))