forked from vlang/v
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transformer: fix using a constant, instead of a fn parameter with the…
… same name (fix vlang#19766) (vlang#19773)
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
vlib/v/tests/const_with_fn_param_with_the_same_name_test.v
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,32 @@ | ||
const zoom_factor = 1.1 | ||
|
||
fn abc(zoom_factor f64) { | ||
assert zoom_factor != 1.1, 'zoom_factor here is the parameter name, not the constant from above' | ||
assert zoom_factor * 10 < 2 | ||
assert zoom_factor * 10 > 0.9 | ||
dump(zoom_factor) | ||
a := if zoom_factor < 1 { 1 } else { -1 } | ||
assert a == 1 | ||
} | ||
|
||
fn def(zfactor f64) { | ||
assert zfactor != zoom_factor, 'zfactor is different than zoom_factor in both name and value' | ||
dump(zfactor) | ||
a := if zfactor < 1 { 1 } else { -1 } | ||
assert a == 1 | ||
} | ||
|
||
fn xyz(zfactor f64) { | ||
assert zfactor != zoom_factor, 'both zfactor and the const zoom_factor should be available, and have different values' | ||
dump(zfactor) | ||
z := if zoom_factor < 1 { 1 } else { -1 } | ||
assert z == -1 | ||
dump(zoom_factor) | ||
assert zoom_factor * 10 > 10.0 | ||
} | ||
|
||
fn test_a_const_should_not_be_used_inside_fn_that_have_parameters_with_the_same_name() { | ||
abc(0.1) | ||
def(0.1) | ||
xyz(0.1) | ||
} |
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