-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move] Fix subtyping bug in typing (#16841)
## Description Fixes a small bug in subtyping ## Test Plan Added a new test, plus everythong else still works --- If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
Showing
3 changed files
with
51 additions
and
4 deletions.
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
11 changes: 11 additions & 0 deletions
11
external-crates/move/crates/move-compiler/tests/move_2024/typing/num_infer.exp
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,11 @@ | ||
error[E04007]: incompatible types | ||
┌─ tests/move_2024/typing/num_infer.move:27:34 | ||
│ | ||
5 │ native public fun vborrow<Element>(v: &vector<Element>, i: u64): ∈ | ||
│ --- Expected: 'u64' | ||
· | ||
26 │ let idx = rnd % (matches.length() as u256); | ||
│ ---- Given: 'u256' | ||
27 │ let game = orders.remove(matches[idx]); | ||
│ ^^^^^^^^^^^^ Invalid call of 'std::vector::vborrow'. Invalid argument for parameter 'i' | ||
|
30 changes: 30 additions & 0 deletions
30
external-crates/move/crates/move-compiler/tests/move_2024/typing/num_infer.move
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,30 @@ | ||
|
||
#[defines_primitive(vector)] | ||
module std::vector { | ||
#[syntax(index)] | ||
native public fun vborrow<Element>(v: &vector<Element>, i: u64): ∈ | ||
#[syntax(index)] | ||
native public fun vborrow_mut<Element>(v: &mut vector<Element>, i: u64): &mut Element; | ||
native public fun remove<Element>(v: &mut vector<Element>, i: u64): Element; | ||
native public fun length<Element>(v: &vector<Element>): u64; | ||
} | ||
|
||
module a::pool { | ||
public struct Order has store, drop { value: u8 } | ||
|
||
public fun find_match( | ||
orders: &mut vector<Order>, | ||
): Option<Order> { | ||
let (mut i, len) = (0, orders.length()); | ||
let mut matches = vector<u64>[]; | ||
|
||
while (i < len) { | ||
i = i + 1; | ||
}; | ||
|
||
let rnd = 100u256; | ||
let idx = rnd % (matches.length() as u256); | ||
let game = orders.remove(matches[idx]); | ||
option::some(game) | ||
} | ||
} |