Skip to content

Commit 3f87d7f

Browse files
committed
Add new error kind for inconsistent inheritance
1 parent 8fb6392 commit 3f87d7f

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

conformance/third_party/conformance.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9988,7 +9988,7 @@
99889988
"concise_description": "Inconsistent types for field `x` inherited from multiple base classes: `int` from `X2`, `str` from `Y2`",
99899989
"description": "Inconsistent types for field `x` inherited from multiple base classes: `int` from `X2`, `str` from `Y2`",
99909990
"line": 65,
9991-
"name": "inconsistent-overload",
9991+
"name": "inconsistent-inheritance",
99929992
"stop_column": 11,
99939993
"stop_line": 65
99949994
}

crates/pyrefly_config/src/error_kind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ pub enum ErrorKind {
140140
/// An error related to the import machinery.
141141
/// e.g. failed to import a module.
142142
ImportError,
143+
/// An inconsistency between inherited fields or methods form multiple base classes.
144+
InconsistentInheritance,
143145
/// An inconsistency between the signature of a function overload and the implementation.
144146
InconsistentOverload,
145147
/// Attempting to access a container with an incorrect index.

pyrefly/lib/alt/class/class_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
19921992
self.error(
19931993
errors,
19941994
cls.range(),
1995-
ErrorInfo::Kind(ErrorKind::InconsistentOverload),
1995+
ErrorInfo::Kind(ErrorKind::InconsistentInheritance),
19961996
format!(
19971997
"Inconsistent types for field `{field_name}` inherited from multiple base classes: {class_and_types_str}",
19981998
),

website/docs/error-kinds.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ An error related to the import mechanism, such as when a module cannot be found.
381381
The error message will include which paths were searched, such as the site package paths.
382382
You may be missing a dependency, or you may need to inform Pyrefly where the module lives. See [Configuration](configuration.mdx) for further information.
383383

384+
## inconsistent-inheritance
385+
386+
When a class inherits from multiple base classes, the inherited fields must be consistent.
387+
388+
Example:
389+
```python
390+
class A:
391+
f: str
392+
class B:
393+
f: int
394+
class C(A, B): ... # error, the field `f` is inconsistent
395+
```
396+
384397
## inconsistent-overload
385398

386399
The signature of a function overload is inconsistent with the implementation.

0 commit comments

Comments
 (0)