Skip to content

Commit 332d2b2

Browse files
fix
1 parent fbf835a commit 332d2b2

8 files changed

Lines changed: 313 additions & 165 deletions

File tree

pyrefly/lib/alt/answers_solver.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use std::cell::RefCell;
99
use std::cmp::Ordering;
10+
use std::collections::HashMap;
1011
use std::fmt;
1112
use std::fmt::Debug;
1213
use std::fmt::Display;
@@ -55,8 +56,10 @@ use crate::module::module_info::ModuleInfo;
5556
use crate::solver::solver::VarRecurser;
5657
use crate::solver::type_order::TypeOrder;
5758
use crate::types::class::Class;
59+
use crate::types::class::ClassDefIndex;
5860
use crate::types::stdlib::Stdlib;
5961
use crate::types::type_info::TypeInfo;
62+
use crate::types::types::TParams;
6063
use crate::types::types::Type;
6164
use crate::types::types::Var;
6265

@@ -378,6 +381,7 @@ pub struct ThreadState {
378381
stack: CalcStack,
379382
/// For debugging only: thread-global that allows us to control debug logging across components.
380383
debug: RefCell<bool>,
384+
placeholder_class_tparams: RefCell<HashMap<ClassDefIndex, Arc<TParams>>>,
381385
}
382386

383387
impl ThreadState {
@@ -386,6 +390,7 @@ impl ThreadState {
386390
cycles: Cycles::new(),
387391
stack: CalcStack::new(),
388392
debug: RefCell::new(false),
393+
placeholder_class_tparams: RefCell::new(HashMap::new()),
389394
}
390395
}
391396
}
@@ -461,6 +466,32 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
461466
&self.thread_state.stack
462467
}
463468

469+
pub fn placeholder_class_tparams(&self, class_idx: ClassDefIndex) -> Option<Arc<TParams>> {
470+
self.thread_state
471+
.placeholder_class_tparams
472+
.borrow()
473+
.get(&class_idx)
474+
.cloned()
475+
}
476+
477+
pub fn insert_placeholder_class_tparams(
478+
&self,
479+
class_idx: ClassDefIndex,
480+
tparams: Arc<TParams>,
481+
) {
482+
self.thread_state
483+
.placeholder_class_tparams
484+
.borrow_mut()
485+
.insert(class_idx, tparams);
486+
}
487+
488+
pub fn remove_placeholder_class_tparams(&self, class_idx: ClassDefIndex) {
489+
self.thread_state
490+
.placeholder_class_tparams
491+
.borrow_mut()
492+
.remove(&class_idx);
493+
}
494+
464495
fn cycles(&self) -> &Cycles {
465496
&self.thread_state.cycles
466497
}

pyrefly/lib/alt/class/classdef.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
7272
let precomputed_tparams = if tparams_require_binding {
7373
None
7474
} else {
75-
Some(self.calculate_class_tparams_no_legacy(name, x.type_params.as_deref(), errors))
75+
Some(self.calculate_class_tparams_no_legacy(
76+
def_index,
77+
name,
78+
x.type_params.as_deref(),
79+
errors,
80+
))
7681
};
7782
Class::new(
7883
def_index,

0 commit comments

Comments
 (0)