-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler-v2] Avoid infinite recursion showing types with receiver fu…
…nctions in presence of errors (#14922) - add test showing Issue #14913 and a simple fix, tracking currently printed vars to prevent recursions, replacing them by .. if they appear recursively (e.g., in constraints) - check for `*error*` in type for instantiation type error message, avoid showing an error message which will be redundant
- Loading branch information
1 parent
a7f73c0
commit 4ea40fe
Showing
5 changed files
with
119 additions
and
13 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
third_party/move/move-compiler-v2/tests/checking/receiver/bad_receiver.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,25 @@ | ||
|
||
Diagnostics: | ||
error: undeclared receiver function `borrow` for type `vector<Entry<K, V>>` | ||
┌─ tests/checking/receiver/bad_receiver.move:25:10 | ||
│ | ||
25 │ &map.entries.borrow(self.index).key | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: undeclared receiver function `lower_bound` for type `OrderedMap<K, V>` | ||
┌─ tests/checking/receiver/bad_receiver.move:29:27 | ||
│ | ||
29 │ let lower_bound = self.lower_bound(key); | ||
│ ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type cannot have type arguments | ||
┌─ tests/checking/receiver/bad_receiver.move:39:36 | ||
│ | ||
39 │ public fun borrow<K, V>(self: &OrderedMao<K, V>, key: &K): &V { | ||
│ ^^^^^^^^^^ | ||
|
||
error: undeclared `0x1::ordered_map::OrderedMao` | ||
┌─ tests/checking/receiver/bad_receiver.move:39:36 | ||
│ | ||
39 │ public fun borrow<K, V>(self: &OrderedMao<K, V>, key: &K): &V { | ||
│ ^^^^^^^^^^ |
50 changes: 50 additions & 0 deletions
50
third_party/move/move-compiler-v2/tests/checking/receiver/bad_receiver.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,50 @@ | ||
module aptos_std::ordered_map { | ||
const EITER_OUT_OF_BOUNDS: u64 = 3; | ||
|
||
struct Entry<K, V> has drop, copy, store { | ||
key: K, | ||
value: V, | ||
} | ||
|
||
enum OrderedMap<K, V> has drop, copy, store { | ||
SortedVectorMap { | ||
entries: vector<Entry<K, V>>, | ||
} | ||
} | ||
|
||
enum Iterator has copy, drop { | ||
End, | ||
Position { | ||
index: u64, | ||
}, | ||
} | ||
|
||
public fun iter_borrow_key<K, V>(self: &Iterator, map: &OrderedMap<K, V>): &K { | ||
assert!(!(self is Iterator::End), EITER_OUT_OF_BOUNDS); | ||
|
||
&map.entries.borrow(self.index).key | ||
} | ||
|
||
public fun find<K, V>(self: &OrderedMap<K, V>, key: &K): Iterator { | ||
let lower_bound = self.lower_bound(key); | ||
if (lower_bound.iter_is_end(self)) { | ||
lower_bound | ||
} else if (lower_bound.iter_borrow_key(self) == key) { | ||
lower_bound | ||
} else { | ||
self.new_end_iter() | ||
} | ||
} | ||
|
||
public fun borrow<K, V>(self: &OrderedMao<K, V>, key: &K): &V { | ||
self.find(key).iter_borrow(self) | ||
} | ||
|
||
public fun new_end_iter<K, V>(self: &OrderedMap<K, V>): Iterator { | ||
Iterator::End | ||
} | ||
|
||
public fun iter_is_end<K, V>(self: &Iterator, _map: &OrderedMap<K, V>): bool { | ||
self is Iterator::End | ||
} | ||
} |
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
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
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