Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions pyrefly/lib/alt/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,13 +687,31 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
) -> Type {
// Based on https://typing.readthedocs.io/en/latest/spec/constructors.html.
let vs = if let Some(hint) = hint {
let vs = self
.solver()
.freshen_class_targs(cls.targs_mut(), self.uniques);

self.is_subset_eq(&self.heap.mk_class_type(cls.clone()), hint.ty());
self.solver().generalize_class_targs(cls.targs_mut());
vs
// Constructor hints may be unions that contain non-instance branches
// (for example `T | Box[T]`). Constraining against the full union can
// bind unrelated type variables and over-specialize this constructor.
// Only pre-specialize from concrete instance branches of the same class.
Comment thread
Arths17 marked this conversation as resolved.
let class_hint = hint.ty().clone().into_unions().into_iter().find_map(|ty| {
if matches!(ty, Type::ClassType(_)) {
if ty.qname() == Some(cls.qname())
&& !ty.contains_type_variable()
&& !ty.may_contain_quantified_var()
{
return Some(ty);
}
}
None
});
Comment thread
Arths17 marked this conversation as resolved.
Outdated
if let Some(class_hint) = class_hint {
let vs = self
.solver()
.freshen_class_targs(cls.targs_mut(), self.uniques);
self.is_subset_eq(&self.heap.mk_class_type(cls.clone()), &class_hint);
self.solver().generalize_class_targs(cls.targs_mut());
vs
} else {
QuantifiedHandle::empty()
}
} else {
QuantifiedHandle::empty()
};
Expand Down
Loading