Skip to content

Commit f476808

Browse files
migeed-zmeta-codesync[bot]
authored andcommitted
Calculate field initialization locally
Summary: We talked in D85778435 about how we don't need to pass the initialization around. I took a stab at it here at it here. Wondering if this looks better than the previous state? Reviewed By: rchen152 Differential Revision: D86102369 fbshipit-source-id: ee11681b42de3e99c38e79b6197fc87e59ea52b3
1 parent 9fbc155 commit f476808

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

pyrefly/lib/alt/class/class_field.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub enum DescriptorBase {
184184
///
185185
/// TODO(stroxler): This type is mostly an artifact of a refactor, it used to be
186186
/// used in `BindingClassField`. We probably can eliminate it.
187-
enum RawClassFieldInitialization {
187+
pub enum RawClassFieldInitialization {
188188
/// At the point where the field is declared, it does not have an initial value. This includes
189189
/// fields declared but not initialized in the class body, and instance-only fields of
190190
/// synthesized classes.
@@ -1336,7 +1336,6 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
13361336
name,
13371337
direct_annotation.as_ref(),
13381338
&ty,
1339-
&initialization,
13401339
initial_value,
13411340
descriptor.is_some(),
13421341
range,
@@ -1430,7 +1429,6 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
14301429
name: &Name,
14311430
direct_annotation: Option<&Annotation>,
14321431
ty: &Type,
1433-
initialization: &ClassFieldInitialization,
14341432
initial_value: &RawClassFieldInitialization,
14351433
is_descriptor: bool,
14361434
range: TextRange,
@@ -1441,7 +1439,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
14411439
name,
14421440
direct_annotation,
14431441
ty,
1444-
initialization,
1442+
initial_value,
14451443
is_descriptor,
14461444
range,
14471445
errors,

pyrefly/lib/alt/class/enums.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use starlark_map::small_set::SmallSet;
2323
use crate::alt::answers::LookupAnswer;
2424
use crate::alt::answers_solver::AnswersSolver;
2525
use crate::alt::class::class_field::ClassAttribute;
26-
use crate::alt::class::class_field::ClassFieldInitialization;
26+
use crate::alt::class::class_field::RawClassFieldInitialization;
2727
use crate::alt::types::class_metadata::ClassMetadata;
2828
use crate::alt::types::class_metadata::EnumMetadata;
2929
use crate::error::collector::ErrorCollector;
@@ -55,15 +55,15 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
5555
&self,
5656
name: &Name,
5757
ty: &Type,
58-
initialization: &ClassFieldInitialization,
58+
initialization: &RawClassFieldInitialization,
5959
) -> bool {
6060
// Names starting but not ending with __ are private
6161
// Names starting and ending with _ are reserved by the enum
6262
if Self::is_mangled_attr(name) || name.starts_with("_") && name.ends_with("_") {
6363
return false;
6464
}
6565
// Enum members must be initialized on the class
66-
if !matches!(*initialization, ClassFieldInitialization::ClassBody(_)) {
66+
if !matches!(*initialization, RawClassFieldInitialization::ClassBody(_)) {
6767
return false;
6868
}
6969
match ty {
@@ -225,7 +225,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
225225
name: &Name,
226226
direct_annotation: Option<&Annotation>,
227227
ty: &Type,
228-
initialization: &ClassFieldInitialization,
228+
initialization: &RawClassFieldInitialization,
229229
is_descriptor: bool,
230230
range: TextRange,
231231
errors: &ErrorCollector,

0 commit comments

Comments
 (0)