Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
9dbad8cc
Commit
9dbad8cc
authored
Jul 07, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect non-covariant return types in overriding cypclass methods
parent
b39ec536
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
11 deletions
+20
-11
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+20
-11
No files found.
Cython/Compiler/Symtab.py
View file @
9dbad8cc
...
@@ -554,20 +554,29 @@ class Scope(object):
...
@@ -554,20 +554,29 @@ class Scope(object):
cpp_override_allowed
=
True
cpp_override_allowed
=
True
continue
continue
# in a cypclass, if the arguments are compatible
# then the whole signature must be identical (return type excluded)
old_declarator
=
alt_entry
.
type
.
declarator_code
(
name
,
for_display
=
1
).
strip
()
new_declarator
=
type
.
declarator_code
(
name
,
for_display
=
1
).
strip
()
if
not
new_declarator
==
old_declarator
:
comparison_message
=
" ---> %s
\
n
vs -> %s"
%
(
new_declarator
,
old_declarator
)
error
(
pos
,
"Cypclass method with compatible arguments but incompatible signature:
\
n
%s"
%
comparison_message
)
if
alt_entry
.
pos
is
not
None
:
error
(
alt_entry
.
pos
,
"Conflicting method is defined here"
)
# Any inherited method is visible
# Any inherited method is visible
# until overloaded by a method with the same signature
# until overloaded by a method with the same signature
if
alt_entry
.
is_inherited
:
if
alt_entry
.
is_inherited
:
if
self
.
is_cyp_class_scope
:
# in a cypclass, if the arguments are compatible, then the new method must actually
# override the inherited method: the whole signature must be identical
old_declarator
=
alt_entry
.
type
.
declarator_code
(
name
,
for_display
=
1
).
strip
()
new_declarator
=
type
.
declarator_code
(
name
,
for_display
=
1
).
strip
()
if
not
new_declarator
==
old_declarator
:
comparison_message
=
" ---> %s
\
n
vs -> %s"
%
(
new_declarator
,
old_declarator
)
error
(
pos
,
"Cypclass method with compatible arguments but incompatible signature:
\
n
%s"
%
comparison_message
)
if
alt_entry
.
pos
is
not
None
:
error
(
alt_entry
.
pos
,
"Conflicting method is defined here"
)
# also, the return type must be covariant
elif
not
type
.
return_type
.
subtype_of_resolved_type
(
alt_entry
.
type
.
return_type
):
error
(
pos
,
"Cypclass method overrides another with incompatible return type"
)
if
alt_entry
.
pos
is
not
None
:
error
(
alt_entry
.
pos
,
"Conflicting method is defined here"
)
previous_alternative_indices
.
append
(
index
)
previous_alternative_indices
.
append
(
index
)
cpp_override_allowed
=
True
cpp_override_allowed
=
True
continue
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment