Skip to content
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

parser, checker: fix var scope in lambda(fix #19860) #19871

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Nov 14, 2023

  1. Fixed Uncaptured variable #19860
  2. Add tests.
fn f(g fn (int) string) {
        println('function returned: ${g(42)}')
}
fn main() {
        s := 'hello world'
        f(|i| s)
}

outputs:

a.v:5:9: warning: unused variable: `s`
    3 | }
    4 | fn main() {
    5 |         s := 'hello world'
      |         ^
    6 |         f(|i| s)
    7 | }
a.v:6:15: error: undefined variable `s`
    4 | fn main() {
    5 |         s := 'hello world'
    6 |         f(|i| s)
      |               ^
    7 | }
    8 |
a.v:6:11: error: `s` used as value
    4 | fn main() {
    5 |         s := 'hello world'
    6 |         f(|i| s)
      |           ^
    7 | }
    8 |

@medvednikov medvednikov merged commit f5bf18c into vlang:master Nov 14, 2023
54 checks passed
@shove70 shove70 deleted the lambda branch November 14, 2023 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncaptured variable
2 participants