Lichen

Changeset

825:8e9566713e1a
2018-06-22 Paul Boddie raw files shortlog changelog graph Fixed accessor tests to raise type errors instead of returning zero.
deducer.py (file) templates/ops.h (file)
     1.1 --- a/deducer.py	Fri Jun 22 15:18:04 2018 +0200
     1.2 +++ b/deducer.py	Fri Jun 22 17:13:29 2018 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  """
     1.5  Deduce types for usage observations.
     1.6  
     1.7 -Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     1.8 +Copyright (C) 2014, 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
     1.9  
    1.10  This program is free software; you can redistribute it and/or modify it under
    1.11  the terms of the GNU General Public License as published by the Free Software
    1.12 @@ -2713,11 +2713,15 @@
    1.13                      accessor = (stored_accessor,)
    1.14                  else:
    1.15                      accessor = (original_accessor,)
    1.16 +            else:
    1.17 +                accessor = None
    1.18  
    1.19              # Apply any test.
    1.20  
    1.21              if test[0] == "test":
    1.22 -                accessor = ("__%s_%s_%s" % test, accessor, test_type)
    1.23 +                test_accessor = accessor = ("__to_error", ("__%s_%s_%s" % test, accessor, test_type))
    1.24 +            else:
    1.25 +                test_accessor = None
    1.26  
    1.27              # Perform the first or final access.
    1.28              # The access only needs performing if the resulting accessor is used.
     2.1 --- a/templates/ops.h	Fri Jun 22 15:18:04 2018 +0200
     2.2 +++ b/templates/ops.h	Fri Jun 22 17:13:29 2018 +0200
     2.3 @@ -1,6 +1,6 @@
     2.4  /* Common operations.
     2.5  
     2.6 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     2.7 +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
     2.8  
     2.9  This program is free software; you can redistribute it and/or modify it under
    2.10  the terms of the GNU General Public License as published by the Free Software
    2.11 @@ -71,6 +71,8 @@
    2.12  __ref __test_common_object__(__ref obj, int pos, int code);
    2.13  __ref __test_common_type__(__ref obj, int pos, int code);
    2.14  
    2.15 +#define __to_error(REF) (REF ? REF : (__raise_type_error(), (__ref) 0))
    2.16 +
    2.17  #define __test_common_instance(OBJ, TYPENAME) (__test_common_instance__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME)))
    2.18  #define __test_common_object(OBJ, TYPENAME) (__test_common_object__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME)))
    2.19  #define __test_common_type(OBJ, TYPENAME) (__test_common_type__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME)))