-
Notifications
You must be signed in to change notification settings - Fork 2
Recursion #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Recursion #96
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -190,6 +190,105 @@ pub async fn analyze_global_stmnt( | |||||
| compiler_flags: vec![], | ||||||
| })]; | ||||||
|
|
||||||
| let data_type = match declared_return_ty { | ||||||
| Some((ty, _)) => ty.clone(), | ||||||
| None => { | ||||||
| let generic_id = scoped_generics_map.new_generic_id(); | ||||||
| scoped_generics_map.constrain_generic_type(generic_id, DataType::Any); | ||||||
| new_generic_types.push(generic_id); | ||||||
|
|
||||||
| DataType::Generic(generic_id) | ||||||
| } | ||||||
| }; | ||||||
| { | ||||||
| let mut symbol_table = backend | ||||||
| .files | ||||||
| .symbol_table | ||||||
| .entry((file_id, file_version)) | ||||||
| .or_default(); | ||||||
|
|
||||||
| insert_symbol_definition( | ||||||
| &mut symbol_table, | ||||||
| &SymbolInfo { | ||||||
| name: name.to_string(), | ||||||
| symbol_type: SymbolType::Function(FunctionSymbol { | ||||||
| arguments: args | ||||||
| .iter() | ||||||
| .enumerate() | ||||||
| .filter_map(|(idx, (arg, span))| match arg { | ||||||
| FunctionArgument::Generic((is_ref, _), (name, _)) => { | ||||||
| Some(( | ||||||
| analysis::FunctionArgument { | ||||||
| name: name.clone(), | ||||||
| data_type: DataType::Generic( | ||||||
| new_generic_types[idx], | ||||||
| ), | ||||||
| is_optional: false, | ||||||
| is_ref: *is_ref, | ||||||
| }, | ||||||
| *span, | ||||||
| )) | ||||||
| } | ||||||
| FunctionArgument::Typed( | ||||||
| (is_ref, _), | ||||||
| (name, _), | ||||||
| (ty, _), | ||||||
| ) => Some(( | ||||||
| analysis::FunctionArgument { | ||||||
| name: name.clone(), | ||||||
| data_type: ty.clone(), | ||||||
| is_optional: false, | ||||||
| is_ref: *is_ref, | ||||||
| }, | ||||||
| *span, | ||||||
| )), | ||||||
| FunctionArgument::Optional( | ||||||
| (is_ref, _), | ||||||
| (name, _), | ||||||
| ty, | ||||||
| _, | ||||||
| ) => Some(( | ||||||
| analysis::FunctionArgument { | ||||||
| name: name.clone(), | ||||||
| data_type: match ty { | ||||||
| Some((ty, _)) => ty.clone(), | ||||||
| None => { | ||||||
| DataType::Generic(new_generic_types[idx]) | ||||||
| } | ||||||
| }, | ||||||
| is_optional: true, | ||||||
| is_ref: *is_ref, | ||||||
| }, | ||||||
| *span, | ||||||
| )), | ||||||
| FunctionArgument::Error => None, | ||||||
| }) | ||||||
| .collect::<Vec<_>>(), | ||||||
| is_public: *is_pub, | ||||||
| compiler_flags: compiler_flags | ||||||
| .iter() | ||||||
| .map(|(flag, _)| flag.clone()) | ||||||
| .collect(), | ||||||
| docs: match contexts.clone().last() { | ||||||
| Some(Context::DocString(doc)) => { | ||||||
| contexts.pop(); | ||||||
| Some(doc.clone()) | ||||||
| } | ||||||
| _ => None, | ||||||
| }, | ||||||
| }), | ||||||
| data_type: data_type.clone(), | ||||||
| is_definition: true, | ||||||
| undefined: false, | ||||||
| span: *name_span, | ||||||
| contexts: vec![], | ||||||
| }, | ||||||
| (file_id, file_version), | ||||||
| 0..=usize::MAX, | ||||||
|
||||||
| 0..=usize::MAX, | |
| name_span.start..=usize::MAX, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential index out of bounds error when accessing
new_generic_types[idx]. The variableidxrepresents the position in theargsarray, butnew_generic_typesonly contains entries for generic and optional arguments without explicit types.For example, with
fun foo(a: Num, b),argshas 2 elements butnew_generic_typeshas only 1. When processing argument at index 0 (a: Num), the code would try to accessnew_generic_types[0]in theTypedbranch (line 236), which doesn't make sense since typed arguments don't add tonew_generic_types. When processing argument at index 1 (b), it would trynew_generic_types[1]which is out of bounds.The old code used
new_generic_types.remove(0)which correctly dequeued generics in order. Consider maintaining a separate counter for generic indices or reverting to the dequeue approach.