-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiler-v2] Avoid infinite recursion showing types with receiver functions in presence of errors #14922
Merged
Merged
[compiler-v2] Avoid infinite recursion showing types with receiver functions in presence of errors #14922
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a typo in the type name
OrderedMao
. This should be corrected toOrderedMap
to match the struct definition and maintain consistency throughout the code.Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the bot correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, in this case it's in a test directory, so I intended it to be incorrect, and it should not be corrected. Their bot should notice a directory named
compiler.*test.*
and consider the possibility that the code is test input code for a compiler.