Skip to content

Commit 2d7cf32

Browse files
committed
Split error message into multiple lines
1 parent 3f87d7f commit 2d7cf32

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
@@ -9985,8 +9985,8 @@
99859985
{
99869986
"code": -2,
99879987
"column": 7,
9988-
"concise_description": "Inconsistent types for field `x` inherited from multiple base classes: `int` from `X2`, `str` from `Y2`",
9989-
"description": "Inconsistent types for field `x` inherited from multiple base classes: `int` from `X2`, `str` from `Y2`",
9988+
"concise_description": "Field `x` has inconsistent types inherited from multiple base classes",
9989+
"description": "Field `x` has inconsistent types inherited from multiple base classes\n Inherited types include:\n `int` from `X2`\n `str` from `Y2`",
99909990
"line": 65,
99919991
"name": "inconsistent-inheritance",
99929992
"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;
@@ -1983,19 +1982,23 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
19831982
let types: Vec<Type> = class_and_types.iter().map(|(_, ty)| ty.clone()).collect();
19841983
let intersect = self.intersects(&types);
19851984
if matches!(intersect, Type::Never(_)) {
1986-
let class_and_types_str = class_and_types
1987-
.iter()
1988-
.map(|(cls, ty)| {
1989-
format!("`{}` from `{}`", self.for_display(ty.clone()), cls)
1990-
})
1991-
.join(", ");
1992-
self.error(
1993-
errors,
1994-
cls.range(),
1995-
ErrorInfo::Kind(ErrorKind::InconsistentInheritance),
1985+
let mut error_msg = vec1![
19961986
format!(
1997-
"Inconsistent types for field `{field_name}` inherited from multiple base classes: {class_and_types_str}",
1987+
"Field `{field_name}` has inconsistent types inherited from multiple base classes"
19981988
),
1989+
"Inherited types include:".to_owned()
1990+
];
1991+
for (cls, ty) in class_and_types.iter() {
1992+
error_msg.push(format!(
1993+
" `{}` from `{}`",
1994+
self.for_display(ty.clone()),
1995+
cls
1996+
));
1997+
}
1998+
errors.add(
1999+
cls.range(),
2000+
ErrorInfo::Kind(ErrorKind::InconsistentInheritance),
2001+
error_msg,
19992002
);
20002003
}
20012004
}

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)