-
Notifications
You must be signed in to change notification settings - Fork 1
v0.4.1: Destructuring Params, Circular Import Diagnostics, Otherwise Lint #21
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
Changes from 2 commits
151d592
5ea6cc7
767fa1f
e24562d
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6339,7 +6339,12 @@ impl Interpreter { | |||||||||||||||||||||||||||
| // Should not reach here due to arity check above | ||||||||||||||||||||||||||||
| Value::Unit | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| func_env.borrow_mut().define(param.name.clone(), value); | ||||||||||||||||||||||||||||
| func_env | ||||||||||||||||||||||||||||
| .borrow_mut() | ||||||||||||||||||||||||||||
| .define(param.name.clone(), value.clone()); | ||||||||||||||||||||||||||||
| if let Some(ref pat) = param.pattern { | ||||||||||||||||||||||||||||
| self.bind_pattern(pat, &value)?; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| func_env | |
| .borrow_mut() | |
| .define(param.name.clone(), value.clone()); | |
| if let Some(ref pat) = param.pattern { | |
| self.bind_pattern(pat, &value)?; | |
| } | |
| // Bind any destructuring pattern before moving the value into the environment | |
| if let Some(ref pat) = param.pattern { | |
| self.bind_pattern(pat, &value)?; | |
| } | |
| func_env | |
| .borrow_mut() | |
| .define(param.name.clone(), value); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,7 +307,15 @@ impl Parser { | |
|
|
||
| if !self.check(&TokenKind::RightParen) { | ||
| loop { | ||
| let name = self.consume_identifier("Expected parameter name")?; | ||
| let (name, pattern) = | ||
| if self.check(&TokenKind::LeftBrace) || self.check(&TokenKind::LeftBracket) { | ||
| let pat = self.parse_pattern()?; | ||
| let synth_name = format!("_destructure_{}", params.len()); | ||
| (synth_name, Some(pat)) | ||
| } else { | ||
| let name = self.consume_identifier("Expected parameter name")?; | ||
| (name, None) | ||
|
Comment on lines
+311
to
+317
|
||
| }; | ||
|
|
||
| let type_annotation = if self.match_token(&[TokenKind::Colon]) { | ||
| Some(self.parse_type()?) | ||
|
|
@@ -325,6 +333,7 @@ impl Parser { | |
| name, | ||
| type_annotation, | ||
| default, | ||
| pattern, | ||
| }); | ||
|
|
||
| if !self.match_token(&[TokenKind::Comma]) { | ||
|
|
@@ -522,6 +531,7 @@ impl Parser { | |
| name: param_name, | ||
| type_annotation, | ||
| default: None, | ||
| pattern: None, | ||
| }); | ||
| } | ||
|
|
||
|
|
||
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.
Function-call parameter binding defines the synthetic "_destructure_N" parameter in the function environment even when the parameter is a destructuring pattern. This makes an internal implementation detail user-visible (it can be referenced from the function body) and can also collide with user-chosen parameter names (e.g., a user explicitly naming a param
_destructure_0). Consider skippingdefine(param.name, ...)whenparam.pattern.is_some()(bind only the pattern vars), or use a non-lexable internal name and ensure it’s never bound in the runtime environment.