Skip to content

Commit 99fd220

Browse files
DanielNoordmeta-codesync[bot]
authored andcommitted
Do not insert Bindings for broken definitions (#2435)
Summary: Closes #2116 This avoid returning this "expression" here: https://github.com/facebook/pyrefly/blob/02dcdc40150998bdbd915fcb2f8051c50a1161f6/pyrefly/lib/binding/bindings.rs#L515 Which avoids adding a `Binding` for something that really doesn't exist. Not sure if this is the best preferred way to handle these panics and bogus code. Pull Request resolved: #2435 Test Plan: Added a testcase. I did run `test.py` but it did not generate any changes. Therefore, I just added the error codes myselff. That seems to have worked. Reviewed By: fangyi-zhou Differential Revision: D93386874 Pulled By: rchen152 fbshipit-source-id: 18b71504a450b8c7320724de7f374f299b4b66ae
1 parent b00bc92 commit 99fd220

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pyrefly/lib/binding/scope.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,12 @@ impl ScopeTrace {
25182518
let mut exportables = SmallMap::new();
25192519
let scope = self.toplevel_scope();
25202520
for (name, static_info) in scope.stat.0.iter_hashed() {
2521+
// Definitions with empty names are not actually accessible and should not be considered
2522+
// as exported. They are likely syntax errors, which are handled elsewhere.
2523+
if name.as_str() == "" {
2524+
continue;
2525+
}
2526+
25212527
let exportable = match scope.flow.get_value_hashed(name) {
25222528
Some(FlowValue { idx: key, .. }) => {
25232529
if let Some(ann) = static_info.annotation() {

pyrefly/lib/test/simple.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,13 @@ a = True if # E: Parse
10691069
"#,
10701070
);
10711071

1072+
testcase!(
1073+
test_syntax_error_resulting_in_empty_defintion,
1074+
r#"
1075+
@:a=1 # E: Parse # E: Could not find name `a`
1076+
"#,
1077+
);
1078+
10721079
testcase!(
10731080
test_mangled_for,
10741081
r#"

0 commit comments

Comments
 (0)