Skip to content

Commit 8b6c78c

Browse files
authored
SymbolTableType::Lambda (#5942)
1 parent 9b133b8 commit 8b6c78c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

compiler/codegen/src/symboltable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub enum SymbolTableType {
8080
Module,
8181
Class,
8282
Function,
83+
Lambda,
8384
Comprehension,
8485
TypeParams,
8586
}
@@ -90,6 +91,7 @@ impl fmt::Display for SymbolTableType {
9091
Self::Module => write!(f, "module"),
9192
Self::Class => write!(f, "class"),
9293
Self::Function => write!(f, "function"),
94+
Self::Lambda => write!(f, "lambda"),
9395
Self::Comprehension => write!(f, "comprehension"),
9496
Self::TypeParams => write!(f, "type parameter"),
9597
// TODO missing types from the C implementation
@@ -493,7 +495,7 @@ impl SymbolTableAnalyzer {
493495
location: None,
494496
});
495497
}
496-
SymbolTableType::Function => {
498+
SymbolTableType::Function | SymbolTableType::Lambda => {
497499
if let Some(parent_symbol) = symbols.get_mut(&symbol.name) {
498500
if let SymbolScope::Unknown = parent_symbol.scope {
499501
// this information is new, as the assignment is done in inner scope
@@ -1140,7 +1142,7 @@ impl SymbolTableBuilder<'_> {
11401142
} else {
11411143
self.enter_scope(
11421144
"lambda",
1143-
SymbolTableType::Function,
1145+
SymbolTableType::Lambda,
11441146
self.line_index_start(expression.range()),
11451147
);
11461148
}

compiler/core/src/bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ op_arg_enum!(
414414
// PrepReraiseS tar = 1,
415415
// TypeVarWithBound = 2,
416416
// TypeVarWithConstraints = 3,
417-
// SetFunctionTypeParams = 4,
417+
SetFunctionTypeParams = 4,
418418
/// Set default value for type parameter (PEP 695)
419419
SetTypeparamDefault = 5,
420420
}

vm/src/frame.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,12 @@ impl ExecutingFrame<'_> {
22862286
bytecode::IntrinsicFunction2::SetTypeparamDefault => {
22872287
crate::stdlib::typing::set_typeparam_default(arg1, arg2, vm)
22882288
}
2289+
bytecode::IntrinsicFunction2::SetFunctionTypeParams => {
2290+
// arg1 is the function, arg2 is the type params tuple
2291+
// Set __type_params__ attribute on the function
2292+
arg1.set_attr("__type_params__", arg2, vm)?;
2293+
Ok(arg1)
2294+
}
22892295
}
22902296
}
22912297

0 commit comments

Comments
 (0)