awk: a function name used as a variable or parameter is accepted

Đang mở
#169 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
cli

Hướng nghiên cứu

Start by locating the parser or name-resolution code that handles function declarations, parameters, and variable or array references; the issue names no source files, so trace those paths from the existing tests. Add regression coverage for the listed cases and run the relevant test suite. Done means these function-name conflicts fail with exit code 1, matching the GNU behavior described.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug gnu-compat good first issue

Function names and variable names share one name space in awk. GNU rejects
assigning to a function name, using it as an array, naming a parameter after
its own function, or calling a parameter as a function. uutils awk accepts all
of these and runs the program.

Reproduction

Rust (incorrect)

$ ./target/release/awk 'function f() { return 1 } BEGIN { f = 2; print f }'
2
$ ./target/release/awk 'function f(f) { return f } BEGIN { print f(3) }'
3

GNU (correct)

$ gawk 'function f() { return 1 } BEGIN { f = 2; print f }'
gawk: cmd. line:1: error: function `f' called with space between name and `(',
or used as a variable or an array
# Exit code: 1
$ gawk 'function f(f) { return f } BEGIN { print f(3) }'
gawk: cmd. line:1: error: function `f': cannot use function name as parameter name
# Exit code: 1

Test

#[test]
fn function_name_as_variable_is_an_error() {
    ucmd()
        .arg("BEGIN { g[1] = 1 } function g() { }")
        .fails_with_code(1);
    ucmd()
        .arg("function h(h) { } BEGIN { }")
        .fails_with_code(1);
}

Exposed by the GNU awk test suite: delfunc, fnamedat, fnarray, fnarray2,
fnasgnm, funsmnam, paramasfunc1, paramasfunc2.

Ngôn ngữ chính
Rust
Star
31
Fork
13
Merge trung bình
23 giờ 42 phút
Pull request đã merge (30 ngày)
29

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của uutils/awk

Tất cả issue của uutils/awk

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.