diff options
author | Garrett Regier <garrett.regier@riftio.com> | 2015-10-04 12:17:40 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2015-10-04 12:17:55 -0400 |
commit | 849f1eef10b18eddaf41c1e0b2cca87bf5d93739 (patch) | |
tree | d36ede7d5b8879699e0a3c391b89a8f4263c456a /giscanner | |
parent | 2699d5116ab5aaf801521c0f6c96bda09a23fb15 (diff) | |
download | gobject-introspection-849f1eef10b18eddaf41c1e0b2cca87bf5d93739.tar.gz |
scanner: Warn and ignore on incorrect optional/nullable/allow-none annotations
These can easily be misunderstood, especially optional.
https://bugzilla.gnome.org/show_bug.cgi?id=752065
Signed-off-by: Garrett Regier <garrett.regier@riftio.com>
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/maintransformer.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index da904cfd..872395a0 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -647,17 +647,32 @@ class MainTransformer(object): self._adjust_container_type(parent, node, annotations) if ANN_NULLABLE in annotations: - node.nullable = True + if self._is_pointer_type(node, annotations): + node.nullable = True + else: + message.warn('invalid "nullable" annotation: ' + 'only valid for pointer types and out parameters', + annotations.position) if ANN_OPTIONAL in annotations: - node.optional = True + if (not isinstance(node, ast.Return) and + node.direction == ast.PARAM_DIRECTION_OUT): + node.optional = True + else: + message.warn('invalid "optional" annotation: ' + 'only valid for out parameters', + annotations.position) if ANN_ALLOW_NONE in annotations: if (node.direction == ast.PARAM_DIRECTION_OUT and not isinstance(node, ast.Return)): node.optional = True - else: + elif self._is_pointer_type(node, annotations): node.nullable = True + else: + message.warn('invalid "allow-none" annotation: ' + 'only valid for pointer types and out parameters', + annotations.position) if (node.direction != ast.PARAM_DIRECTION_OUT and (node.type.target_giname == 'Gio.AsyncReadyCallback' or |