Repository navigation
fix(hy-check): reject statically-known non-string format and input operands on fmt scan family (fixes #4265) - #4267
Open
Anekenonso wants to merge 1 commit into
Conversation
…erands on fmt scan family (fixes limitlessprojects#4265)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary & Motivation
Fixes #4265.
While PR #4196 (resolving #4195) introduced
Collector::nonstring_format_kind(&Expr)to reject statically-known non-string expressions (such as resolved integer locals or binary operations) passed tofmt.printf,fmt.sprintf,fmt.eprintf,fmt.errorf, andfmt.fprintf, the scan-family arms incompiler/crates/hy-check/src/buildable.rs(lines 8107–8240) were omitted.As demonstrated in Issue #4265, passing non-string operands via local variables (e.g.
x := 42) or binary expressions (e.g.40 + 2) tofmt.scanf,fmt.sscanf,fmt.fscanf,fmt.sscan, orfmt.sscanlnpassedhyb checkwith 0 diagnostics (Verdict: Accept). Emitted Go code calledfmt.Scanf(x, ...),fmt.Sscanf(x, ...),fmt.Fscanf(..., x, ...), orfmt.Sscan(x, ...), which fails downstreamgo buildwith type mismatch errors (violating GUARANTEES.md Row 13 BUILDABLE).Changes
buildable.rs:fmt.scanf: checksself.nonstring_format_kind(bare)and rejects statically-known non-string format operands withHYB-E1002.fmt.sscanf: checksself.nonstring_format_kindon bothbare0(input string) andbare1(format string), rejecting non-string operands withHYB-E1002.fmt.fscanf: checksself.nonstring_format_kind(bare1)(format string) and rejects non-string operands withHYB-E1002.fmt.sscan&fmt.sscanln: checksself.nonstring_format_kind(bare0)(input string) and rejects non-string operands withHYB-E1002.compiler/crates/hy-check/tests/fmt_scan_family_buildable.rswith 7 new negative regression tests covering non-string local variables (x := 42,b := true), binary operations (40 + 2,10 * 2), across all scan functions.fmt_str := "%d",input_str := "42") continue to compile and pass with 0 errors.Verification
cargo test -p hy-check --test fmt_scan_family_buildable: 21 passed / 0 failed.cargo test -p hy-check --test fmt_special_member_calls_buildable: 21 passed / 0 failed.cargo check -p hy-check: 0 errors.