Skip to content

Commit 585bcb9

Browse files
committed
Split error message into multiple lines
1 parent 30d054d commit 585bcb9

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

conformance/third_party/conformance.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10045,8 +10045,8 @@
1004510045
{
1004610046
"code": -2,
1004710047
"column": 7,
10048-
"concise_description": "Inconsistent types for field `x` inherited from multiple base classes: `int` from `X2`, `str` from `Y2`",
10049-
"description": "Inconsistent types for field `x` inherited from multiple base classes: `int` from `X2`, `str` from `Y2`",
10048+
"concise_description": "Field `x` has inconsistent types inherited from multiple base classes",
10049+
"description": "Field `x` has inconsistent types inherited from multiple base classes\n Inherited types include:\n `int` from `X2`\n `str` from `Y2`",
1005010050
"line": 65,
1005110051
"name": "inconsistent-inheritance",
1005210052
"stop_column": 11,

pyrefly/lib/alt/class/class_field.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::iter;
1111
use std::sync::Arc;
1212

1313
use dupe::Dupe;
14-
use itertools::Itertools;
1514
use pyrefly_derive::TypeEq;
1615
use pyrefly_derive::VisitMut;
1716
use pyrefly_python::dunder;
@@ -1971,19 +1970,23 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
19711970
let types: Vec<Type> = class_and_types.iter().map(|(_, ty)| ty.clone()).collect();
19721971
let intersect = self.intersects(&types);
19731972
if matches!(intersect, Type::Never(_)) {
1974-
let class_and_types_str = class_and_types
1975-
.iter()
1976-
.map(|(cls, ty)| {
1977-
format!("`{}` from `{}`", self.for_display(ty.clone()), cls)
1978-
})
1979-
.join(", ");
1980-
self.error(
1981-
errors,
1982-
cls.range(),
1983-
ErrorInfo::Kind(ErrorKind::InconsistentInheritance),
1973+
let mut error_msg = vec1![
19841974
format!(
1985-
"Inconsistent types for field `{field_name}` inherited from multiple base classes: {class_and_types_str}",
1975+
"Field `{field_name}` has inconsistent types inherited from multiple base classes"
19861976
),
1977+
"Inherited types include:".to_owned()
1978+
];
1979+
for (cls, ty) in class_and_types.iter() {
1980+
error_msg.push(format!(
1981+
" `{}` from `{}`",
1982+
self.for_display(ty.clone()),
1983+
cls
1984+
));
1985+
}
1986+
errors.add(
1987+
cls.range(),
1988+
ErrorInfo::Kind(ErrorKind::InconsistentInheritance),
1989+
error_msg,
19871990
);
19881991
}
19891992
}

pyrefly/lib/test/class_subtyping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class Foo:
270270
class Bar:
271271
p: str
272272
273-
class Both(Foo, Bar): # E: Inconsistent types for field `p` inherited from multiple base classes: `int` from `Foo`, `str` from `Bar`
273+
class Both(Foo, Bar): # E: Field `p` has inconsistent types inherited from multiple base classes
274274
...
275275
"#,
276276
);

0 commit comments

Comments
 (0)