-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Let variables #1095
Merged
DarshalShetty
merged 13 commits into
carbon-language:trunk
from
DarshalShetty:let-variables
Mar 11, 2022
Merged
Let variables #1095
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
869d601
Modify parser and AST nodes to include let statement
DarshalShetty 7e3dbc5
Implement let variables
DarshalShetty ba0e976
Remove redundant code in fail_match_choice test
DarshalShetty 3e4d563
Add comment for has_value_category()
DarshalShetty 8c93331
Apply suggestions from code review
DarshalShetty 62f5dee
clang-format changes
DarshalShetty 2c1dbce
Update comments for new BindingPattern methods
DarshalShetty 5211f9f
Implement nested vars in patterns
DarshalShetty 96c5dd9
Apply suggestions from @geoffromer's code review
DarshalShetty b939fbd
Merge branch 'trunk' into let-variables
DarshalShetty 50cf6a2
Implement changes from code review.
DarshalShetty 7f138dc
Merge branch 'trunk' into let-variables
DarshalShetty a9c3627
Remove maybe_var_pattern grammar rule
DarshalShetty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
executable_semantics/testdata/let/fail_function_args.carbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
// Exceptions. See /LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// RUN: %{not} %{executable_semantics} %s 2>&1 | \ | ||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s | ||
// RUN: %{not} %{executable_semantics} --trace %s 2>&1 | \ | ||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s | ||
// AUTOUPDATE: %{executable_semantics} %s | ||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/let/fail_function_args.carbon:16: Cannot assign to rvalue 'y' | ||
|
||
package ExecutableSemanticsTest api; | ||
|
||
fn f((var x: i32, y: i32)) -> i32 { | ||
x = 0; | ||
y = 0; | ||
return x - 1; | ||
} | ||
|
||
fn Main() -> i32 { | ||
var t: auto = (1, 2); | ||
return f(t); | ||
} |
19 changes: 19 additions & 0 deletions
19
executable_semantics/testdata/let/fail_global_assign.carbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
// Exceptions. See /LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// RUN: %{not} %{executable_semantics} %s 2>&1 | \ | ||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s | ||
// RUN: %{not} %{executable_semantics} --trace %s 2>&1 | \ | ||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s | ||
// AUTOUPDATE: %{executable_semantics} %s | ||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/let/fail_global_assign.carbon:17: Cannot assign to rvalue 'x' | ||
|
||
package ExecutableSemanticsTest api; | ||
|
||
let x: i32 = 10; | ||
|
||
fn Main() -> i32 { | ||
x = 0; | ||
return 0; | ||
} |
18 changes: 18 additions & 0 deletions
18
executable_semantics/testdata/let/fail_local_assign.carbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
// Exceptions. See /LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// RUN: %{not} %{executable_semantics} %s 2>&1 | \ | ||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s | ||
// RUN: %{not} %{executable_semantics} --trace %s 2>&1 | \ | ||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s | ||
// AUTOUPDATE: %{executable_semantics} %s | ||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/let/fail_local_assign.carbon:16: Cannot assign to rvalue 'x' | ||
|
||
package ExecutableSemanticsTest api; | ||
|
||
fn Main() -> i32 { | ||
let x: auto = 10; | ||
x = 0; | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Non-blocking observation: I'd prefer if we could always get this from the typechecker, rather than sometimes as a constructor parameter, but I think this is a consequence of some pre-existing problems that are out of scope for this PR.